我想在键盘出现时向上移动按钮
我想在键盘出现时向上移动按钮并在键盘消失时向下移动 当前键盘正在通过按钮。 查看截图 我已经尝试了下面的功能,但不是键盘以上的功能。我想在键盘出现时向上移动按钮
<android:windowSoftInputMode="adjustPan">
android:windowSoftInputMode="adjustResize"
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/slide_name_title"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:layout_marginTop="45dp"
android:textColor="#283D65"
android:textSize="@dimen/slide_title"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/slide_1_1_title"
android:layout_marginTop="10dp"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:textColor="#8E8E8E"
android:textSize="@dimen/slide_title1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:text="@string/slide_1_desc"
android:textColor="#2A3042"
android:textSize="@dimen/slide_desc" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Full Name (Eg. John Smith)"
android:background="@color/white"
android:textColorHint="#8E8E8E"
android:maxLength="25"
android:maxLines="1"
android:layout_marginTop="20dp"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:textColor="#000000"
android:id="@+id/editTextUserName" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_above="@+id/password"
android:background="#E0E0E0"
android:layout_below="@+id/login_button"></View>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp"
>
<ViewFlipper
android:id="@+id/viewFlipper"
android:layout_width="310dp"
android:layout_height="48dp"
>
<Button
android:text="नमस्ते"
android:backgroundTint="#2DC9D7"
android:layout_width="310dp"
android:layout_height="48dp"
android:textSize="20dp"
android:background="@drawable/button_corner"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/btn_name_next"/>
<Button
android:text="Hello"
android:backgroundTint="#2DC9D7"
android:layout_width="310dp"
android:layout_height="48dp"
android:background="@drawable/button_corner"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/btn_name_next1"/>
<Button
android:text="Hi"
android:backgroundTint="#2DC9D7"
android:layout_width="310dp"
android:layout_height="48dp"
android:background="@drawable/button_corner"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/btn_name_next2"/>
</ViewFlipper>
</RelativeLayout>
</RelativeLayout>
把按钮的帧结构和FrameLayout里的真
尝试但不工作 – Neeraj
尝试使用scrollview。既然你已经设置了android:windowSoftInputMode =“adjustResize”它已经试图把所有上面的键盘,但相对布局不好。将您的根相对布局放入滚动视图中。 –
设置fitSystemWindows属性试试这个:
,滚动型包装你的顶面布置图:离开按钮布局
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fillViewport="false">
<LinearLayout>
</LinearLayout>
</ScrollView>
现在在按钮布局:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/scrollview"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical">
</RelativeLayout>
而且在清单:
android:windowSoftInputMode="adjustResize"
出于某种原因,这对我的作品..
编辑
调用此:getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
不能正常工作 – Neeraj
scrollview应该在您的顶部标签'Relativelayout'....and应用''android:layout_alignParentBottom =“true”'到包含按钮的底部布局。 – rafsanahmad007
是相同的,但没有同时键盘出现 – Neeraj
使用此代码它将解决您的问题并评论我是否有任何问题。
以下行使用您的活动在Android清单文件
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
以下布局代码工作
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="Welcome"
android:textColor="#283D65"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="Happy To see you! Let's get to know each other"
android:textColor="#8E8E8E"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="What should we call you?"
android:textColor="#2A3042"
android:textSize="13sp" />
<EditText
android:id="@+id/editTextUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:hint="Full Name (Eg. John Smith)"
android:inputType="textPersonName"
android:maxLength="25"
android:maxLines="1"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:textColor="#000000"
android:textColorHint="#8E8E8E" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_above="@+id/password"
android:layout_below="@+id/login_button"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:background="#E0E0E0"></View>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp"
android:gravity="center"
android:orientation="vertical">
<ViewFlipper
android:id="@+id/viewFlipper"
android:layout_width="310dp"
android:layout_height="48dp">
<Button
android:id="@+id/btn_name_next"
android:layout_width="310dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#000"
android:backgroundTint="#2DC9D7"
android:text="नमस्ते"
android:textSize="20dp" />
<Button
android:id="@+id/btn_name_next1"
android:layout_width="310dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#000"
android:backgroundTint="#2DC9D7"
android:text="Hello" />
<Button
android:id="@+id/btn_name_next2"
android:layout_width="310dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#000"
android:backgroundTint="#2DC9D7"
android:text="Hi" />
</ViewFlipper>
</RelativeLayout>
必须有只有一个滚动视图孩子:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 2"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 3"
/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 4"
/>
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 5"
/>
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 6"
/>
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 7"
/>
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 8"
/>
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 9"
/>
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 10"
/>
</LinearLayout>
</ScrollView>
为什么你里面ViewFlipper添加按钮? –
将相对布局放在'ScrollView'中,并将'ScrollView'保留为父视图 –
@Magesh Pandian查看鳍状肢用于按钮文本中的动画。 – Neeraj