2017-08-07 34 views
0

我有设计如下代码的布局,但有EditText,Listview和3按钮。 因此,这3个按钮全部添加到父布局的底部。但是当我点击EditText写东西时,那些按钮就像附加的图像一样显示。但我需要将该按钮保留在底部而不会出现在移动键盘的上方。按钮没有显示在Android的底部

<?xml version="1.0" encoding="utf-8"?> 
<layout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<RelativeLayout 
    android:id="@+id/mainLay" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical"> 



    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/layout" 
     android:orientation="vertical" 
     android:padding="@dimen/activity"> 

     <LinearLayout 
      android:id="@+id/top" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:padding="4dp"> 

      <EditText 
       android:id="@+id/vehicleId" 
       android:layout_width="0dp" 
       android:layout_height="@dimen/height_row" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="0.5" 
       android:background="@null" 
       android:gravity="center_vertical" 
       android:hint="@string/enter_vehicle_id" 
       android:lines="1" 
       android:paddingLeft="6dp" 
       android:singleLine="true" 
       android:textColor="@color/darkGrey" 
       android:textColorHint="@color/darkGrey" 
       android:textSize="@dimen/normal" 
       app:font="@{@string/font_roboto_regular}" /> 

      <View 
       android:layout_width="1dp" 
       android:layout_height="match_parent" 
       android:background="@color/viewColor" /> 

      <EditText 
       android:id="@+id/mileage" 
       android:layout_width="0dp" 
       android:layout_height="@dimen/height_row" 
       android:layout_marginLeft="5dp" 
       android:layout_marginStart="5dp" 
       android:layout_weight="1" 
       android:background="@null" 
       android:hint="@string/enter_mileage" 
       android:imeOptions="actionNext" 
       android:inputType="text" 
       android:lines="1" 
       android:paddingLeft="5dp" 
       android:singleLine="true" 
       android:textColor="@color/darkGrey" 
       android:textColorHint="@color/darkGrey" 
       android:textSize="@dimen/normal" 
       app:font="@{@string/font_roboto_regular}" /> 

     </LinearLayout> 

     <View 
      android:id="@+id/topView" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:layout_below="@+id/top" 
      android:background="@color/viewColor" /> 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/bottomView" 
      android:layout_below="@+id/top" 
      android:layout_marginTop="10dp" 
      android:paddingTop="@dimen/activity" /> 

     <LinearLayout 
      android:id="@id/bottomView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginTop="10dp" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="bottom" 
       android:orientation="horizontal"> 

       <Button 
        android:id="@+id/scan" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:layout_weight="1" 
       android:background="@drawable/sel_rounded_rectangle_color1_2" 
        android:gravity="center" 
        android:minHeight="@dimen/min_touch" 
        android:text="@string/scan" 
        android:textAllCaps="false" 
        android:textColor="@color/white" 
        android:textSize="22sp" 
        app:font="@{@string/font_roboto_regular}" /> 

       <Button 
        android:id="@+id/manual" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:layout_marginLeft="@dimen/activity" 
        android:layout_marginStart="@dimen/activity" 
        android:layout_weight="1" 
        android:background="@drawable/sel_rounded_rectangle_color1_2" 
        android:gravity="center" 
        android:minHeight="@dimen/min_touch" 
        android:text="@string/manual" 
        android:textAllCaps="false" 
        android:textColor="@color/white" 
        android:textSize="22sp" 
        app:font="@{@string/font_roboto_regular}" /> 

      </LinearLayout> 

      <Button 
       android:id="@+id/submit" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:layout_marginTop="@dimen/activity" 
       android:background="@drawable/sel_rounded_rectangle_color1_2" 
       android:gravity="center" 
       android:minHeight="@dimen/min_touch" 
       android:text="@string/submit" 
       android:textAllCaps="false" 
       android:textColor="@color/white" 
       android:textSize="22sp" 
       app:font="@{@string/font_roboto_regular}" /> 
     </LinearLayout> 

     <ProgressBar 
      android:id="@+id/progressBar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:indeterminate="true" 
      android:visibility="gone" /> 
    </RelativeLayout> 

</RelativeLayout> 
</layout> 

在此先感谢。

+0

你有没有尝试使用的LinearLayout通过你的布局? – Mocas

+0

如果我试过,然后listview不能设置底部视图 – CarinaMj

+1

https://stackoverflow.com/questions/13277785/how-to-have-a-fixed-footer-with-scrollview-in-android可能会帮助你。即按钮应该在页脚 –

回答

2

添加windowSoftInputMode = “adjustPan”到您的活动。如果它是片段,请将其添加到conatainer活动中。

<activity android:name="MyActivity" 
... 
android:windowSoftInputMode="adjustPan" 
... 
</activity> 
+0

你是什么意思,如果这个片段? – CarinaMj

+0

如果编辑文本位于片段的视图中。将该属性添加到包含您的片段的活动。 – SunSun

+0

如何为一个片段做到这一点? – CarinaMj

1

只需在此的Manifest.xml代码添加到您的活动标签文件

<activity 
... 
android:windowSoftInputMode="adjustPan"> 
</activity> 
+0

这是为片段,那么我怎么可以添加此代码? – CarinaMj

+1

添加到附加的片段的哪个活动中。 – Fr099y

0

在您的清单,

<activity 
    .. 
    android:windowSoftInputMode="adjustNothing"> 
</activity> 

请注意,这会停止推布局并重叠 按钮显示软键盘时。

1

尝试一下本作的片段:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);