2016-01-02 37 views
0

我遇到了Android手机的问题,该手机有一个底部操作栏,应用程序屏幕被手机中的操作栏截断。请参阅下面的屏幕截图,以更好地描述我的问题。该按钮被操作栏切断。具有底部操作栏的Android手机的布局问题

The button at the bottom of my app screen is cut off by the action bar

下面是我的布局xml文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/root_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@mipmap/main_bg" 
    tools:context="com.myapp.SeatsActivity"> 

    <RelativeLayout 
     android:id="@+id/actionbar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/irctc_actionbar_height" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/imageView4" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="6dp" 
      android:onClick="onClickgoHome" 
      android:src="@mipmap/iconhome" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="4dp" 
      android:layout_toLeftOf="@+id/button11" 
      android:layout_toRightOf="@+id/imageView4" 
      android:gravity="center" 
      android:text="SEAT AVAILABILITY" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <ImageView 
      android:id="@+id/imageView5" 
      android:layout_width="@dimen/irctc_actionbar_height" 
      android:layout_height="@dimen/irctc_actionbar_height" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:background="@drawable/trans_button" 
      android:clickable="true" 
      android:onClick="onClickShare" 
      android:padding="4dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/share" /> 

     <Button 
      android:id="@+id/button11" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/imageView5" 
      android:onClick="onClickDate" 
      android:text="date:" 
      android:textColor="@color/white" /> 

    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/horizontal_line" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/actionbar_layout" 
     android:background="@color/white" 
     android:orientation="vertical" /> 

    <TextView 
     android:id="@+id/txtview_trainname" 
     android:layout_width="match_parent" 
     android:layout_height="36dp" 
     android:layout_below="@+id/horizontal_line" 
     android:background="@color/irctc_menu_bg_color" 
     android:gravity="center" 
     android:text="Train Name" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/white" 
     android:textStyle="bold" /> 

    <LinearLayout 
     android:id="@+id/hr2" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/txtview_trainname" 
     android:background="@color/white" 
     android:orientation="vertical" /> 

    <TextView 
     android:id="@+id/txtview_fromtostation" 
     android:layout_width="match_parent" 
     android:layout_height="36dp" 
     android:layout_below="@+id/hr2" 
     android:background="@color/irctc_menu_bg_color" 
     android:gravity="center" 
     android:text="Station Name" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/white" 
     android:textStyle="bold" /> 

    <LinearLayout 
     android:id="@+id/hr3" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/txtview_fromtostation" 
     android:background="@color/white" 
     android:orientation="vertical" /> 

    <LinearLayout 
     android:id="@+id/layout_table_header" 
     android:layout_width="match_parent" 
     android:layout_height="46dp" 
     android:layout_below="@+id/hr3" 
     android:background="@color/irctc_menu_bg_color" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="3" 
      android:gravity="center" 
      android:text="Date" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtview_class1" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="center" 
      android:text="class1" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtview_class2" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="center" 
      android:text="class2" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/layout_bottom" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:layout_above="@+id/btn_express_book" 
     android:layout_alignParentBottom="false" 
     android:background="@color/irctc_menu_bg_color"> 

     <TextView 
      android:id="@+id/textView9" 
      android:layout_width="70dp" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Quota:" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" /> 

     <Button 
      android:id="@+id/btn_quota" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/imageView9" 
      android:layout_toRightOf="@+id/textView9" 
      android:background="@drawable/trans_button" 
      android:onClick="onClickQuota" 
      android:text="Selected Quota" 
      android:textColor="@color/white" /> 

     <ImageView 
      android:id="@+id/imageView8" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:background="@drawable/trans_button" 
      android:clickable="true" 
      android:onClick="onClickTrainSchedule" 
      android:paddingBottom="4dp" 
      android:paddingTop="4dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/train_schedule" /> 

     <ImageView 
      android:id="@+id/imageView9" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_toLeftOf="@+id/imageView8" 
      android:background="@drawable/trans_button" 
      android:clickable="true" 
      android:onClick="onClickFareEnquery" 
      android:paddingBottom="4dp" 
      android:paddingTop="4dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/fair_enquiry" /> 

    </RelativeLayout> 

    <ListView 
     android:id="@+id/listview_seatcell" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/adView" 
     android:layout_below="@+id/layout_table_header" /> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/layout_bottom" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id" /> 

    <Button 
     android:id="@+id/btn_express_book" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="4dp" 
     android:layout_marginTop="4dp" 
     android:background="@drawable/irctc_button" 
     android:onClick="onClickExpressBook" 
     android:paddingBottom="10dp" 

     android:paddingLeft="40dp" 
     android:paddingRight="40dp" 
     android:paddingTop="10dp" 
     android:text="Express Book!" 
     android:textColor="#ffffff" /> 

</RelativeLayout> 

我在这里做错了什么?我需要对xml进行哪些更改以适应带有操作栏的手机?

+0

你为什么有'和'ID LinearLayout' = HR2 '和'id = hr3',当里面没有视图。拥有它们是没有用的。 –

+0

你尝试使用scrollview吗? –

+0

问题不在于这里的小屏幕大小,所以使用scrollview不会帮助。问题是该按钮与父级底部对齐,但仍然被切断。 – tbag

回答

1

尝试在布局内设置android:layout_alignParentBottom =“false”到android:layout_alignParentBottom =“true”。所以像这样的东西。

<RelativeLayout 
    android:id="@+id/layout_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:layout_above="@+id/btn_express_book" 
    android:layout_alignParentBottom="true" 
    android:background="@color/irctc_menu_bg_color"> 
+0

我已经为按钮设置了'android:layout_alignParentBottom =“true”'。你的意思是把它设置为相关布局? – tbag

+0

是在相对的布局尝试它,对不起,我的帖子不清楚 –

+0

我试过这个,但它没有奏效。 – tbag

1

我已将ScrollView添加到您的ViewGroup。检查它:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/root_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@mipmap/main_bg" 
    tools:context="com.myapp.SeatsActivity"> 

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    <RelativeLayout 
     android:id="@+id/actionbar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/irctc_actionbar_height" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/imageView4" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="6dp" 
      android:onClick="onClickgoHome" 
      android:src="@mipmap/iconhome" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="4dp" 
      android:layout_toLeftOf="@+id/button11" 
      android:layout_toRightOf="@+id/imageView4" 
      android:gravity="center" 
      android:text="SEAT AVAILABILITY" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <ImageView 
      android:id="@+id/imageView5" 
      android:layout_width="@dimen/irctc_actionbar_height" 
      android:layout_height="@dimen/irctc_actionbar_height" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:background="@drawable/trans_button" 
      android:clickable="true" 
      android:onClick="onClickShare" 
      android:padding="4dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/share" /> 

     <Button 
      android:id="@+id/button11" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/imageView5" 
      android:onClick="onClickDate" 
      android:text="date:" 
      android:textColor="@color/white" /> 

    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/horizontal_line" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/actionbar_layout" 
     android:background="@color/white" 
     android:orientation="vertical" /> 

    <TextView 
     android:id="@+id/txtview_trainname" 
     android:layout_width="match_parent" 
     android:layout_height="36dp" 
     android:layout_below="@+id/horizontal_line" 
     android:background="@color/irctc_menu_bg_color" 
     android:gravity="center" 
     android:text="Train Name" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/white" 
     android:textStyle="bold" /> 

    <LinearLayout 
     android:id="@+id/hr2" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/txtview_trainname" 
     android:background="@color/white" 
     android:orientation="vertical" /> 

    <TextView 
     android:id="@+id/txtview_fromtostation" 
     android:layout_width="match_parent" 
     android:layout_height="36dp" 
     android:layout_below="@+id/hr2" 
     android:background="@color/irctc_menu_bg_color" 
     android:gravity="center" 
     android:text="Station Name" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/white" 
     android:textStyle="bold" /> 

    <LinearLayout 
     android:id="@+id/hr3" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/txtview_fromtostation" 
     android:background="@color/white" 
     android:orientation="vertical" /> 

    <LinearLayout 
     android:id="@+id/layout_table_header" 
     android:layout_width="match_parent" 
     android:layout_height="46dp" 
     android:layout_below="@+id/hr3" 
     android:background="@color/irctc_menu_bg_color" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="3" 
      android:gravity="center" 
      android:text="Date" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtview_class1" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="center" 
      android:text="class1" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtview_class2" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="center" 
      android:text="class2" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/layout_bottom" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:layout_above="@+id/btn_express_book" 
     android:layout_alignParentBottom="false" 
     android:background="@color/irctc_menu_bg_color"> 

     <TextView 
      android:id="@+id/textView9" 
      android:layout_width="70dp" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Quota:" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" /> 

     <Button 
      android:id="@+id/btn_quota" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/imageView9" 
      android:layout_toRightOf="@+id/textView9" 
      android:background="@drawable/trans_button" 
      android:onClick="onClickQuota" 
      android:text="Selected Quota" 
      android:textColor="@color/white" /> 

     <ImageView 
      android:id="@+id/imageView8" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:background="@drawable/trans_button" 
      android:clickable="true" 
      android:onClick="onClickTrainSchedule" 
      android:paddingBottom="4dp" 
      android:paddingTop="4dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/train_schedule" /> 

     <ImageView 
      android:id="@+id/imageView9" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_toLeftOf="@+id/imageView8" 
      android:background="@drawable/trans_button" 
      android:clickable="true" 
      android:onClick="onClickFareEnquery" 
      android:paddingBottom="4dp" 
      android:paddingTop="4dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/fair_enquiry" /> 

    </RelativeLayout> 

    <ListView 
     android:id="@+id/listview_seatcell" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/adView" 
     android:layout_below="@+id/layout_table_header" /> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/layout_bottom" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id" /> 

    <Button 
     android:id="@+id/btn_express_book" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="4dp" 
     android:layout_marginTop="4dp" 
     android:background="@drawable/irctc_button" 
     android:onClick="onClickExpressBook" 
     android:paddingBottom="10dp" 

     android:paddingLeft="40dp" 
     android:paddingRight="40dp" 
     android:paddingTop="10dp" 
     android:text="Express Book!" 
     android:textColor="#ffffff" /> 

    </RelativeLayout> 
</ScrollView> 

希望它能帮助

+0

问题不在于此处的小屏幕尺寸。问题是该按钮与父级底部对齐,但仍然被切断。 – tbag

+0

尝试使用滚动视图在我的代码中 – piotrek1543

+0

同样的问题发生在像Nexus 6p这样的大型手机屏幕上。我知道使用scrollview会解决这个问题,但我试图找到一个解决方案,而不使用scrollview。 – tbag

1
  1. 不要使用RelativeLayout模仿LinearLayout

您的所有视图都不重叠,它们都不需要与其他视图进行任何特殊的对齐。使用layout_belowlayout_above重新创建令人困惑。您可以使用LinearLayout来完成布局中的任何操作,除非可能使用两个动作条(但即使这些动作条也可以使用LinearLayout),它们会更加清晰。

  1. 请勿使用空的LinearLayout s作为水平分隔符。

如果您必须使用视图,请使用View。但如果你像我在#1建议做这个LinearLayout里面,那么你可能根本不需要的观点,你可以使用

android:showDividers="middle" 
android:divider="@drawable/hr" 

res/drawable/hr.xml

<shape android:shape="rectangle"> 
    <size android:height="1dp" /> 
    <solid android:color="@android:color/white" /> 
</shape> 
  • 永远不要使用wrap_content作为ListView的高度。
  • ListView对孩子的事情一无所知。告诉它需要包含它们的高度没有任何意义,并且ListView只是试图猜测。您应始终使用静态值match_parent或允许它使用layout_weight(如果使用LinearLayout)或其他视图边界(如果使用RelativeLayout)填充任意空间。


    结合上述所有的,我觉得你的布局应该结束这样看(只有相关部分所示):

    <LinearLayout android:orientation="vertical" ...> 
        <RelativeLayout ... /> <!-- Top action bar --> 
        <TextView ... /> 
        <TextView ... /> 
        <LinearLayout android:orientation="horizontal" ... /> <!-- table header --> 
        <ListView 
         android:layout_height="0dp" 
         android:layout_weight="1" 
         ... /> 
        <AdView ... /> 
        <RelativeLayout ... /> <!-- bottom action bar --> 
        <Button ... /> <!-- The one that is currently cut off --> 
    </LinearLayout>