我已经阅读了所有可以找到的内容,但我无法弄清楚。我有一个带标题的XML,然后是一个列表视图,然后在底行有2个按钮。为了使布局看起来完美,我对列表视图的大小(467dp)进行了“硬编码”。这在我的三星Galaxy S4上很好,但是我不确定在尺寸稍有不同的其他手机上看起来是否合适。我在Galaxy 8“标签上对其进行了测试,但外观并不正确。然后在10.1”标签上进行了测试,同样(它再次)外观不正确。基本上,底部按钮在屏幕中间。我通过为sw600dp和sw720dp创建布局来解决此问题。对于每一个,我都必须为listview硬编码一个不同的大小。在我看来,有一种更好的方法来获得可以在任何设备上显示(相对)相同的heading-listview-button XML。谁能告诉我如何更改XML,而不必硬编码listview的大小?
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title_line"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="@string/workout_locations">
</TextView>
<ListView
android:id="@+id/location_list"
android:layout_width="match_parent"
android:layout_height="467dp"
android:longClickable="true" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/help_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/help_description"
/>
<ImageButton
android:id="@+id/add_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/add_description"
/>
</LinearLayout>
</LinearLayout>
我想知道这是否有帮助:
确保整个布局是relativeLayout,然后在其中放入listview
<ListView
android:id="@+id/location_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp" // the size of the buttons height
android:longClickable="true" >
</ListView>
在它下面的另一个相对布局,其中包含按钮。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/help_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/help_description"
/>
<ImageButton
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/add_description"
/>
如果仍然引起问题,则可以编写:
android:layout_above="@+id/relButtonLayout"
在列表视图中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句