多种屏幕尺寸和XML布局

UFGator

我已经阅读了所有可以找到的内容,但我无法弄清楚。我有一个带标题的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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过使用多种布局在Android中支持多种屏幕尺寸

支持多种屏幕尺寸和方向

在Android中支持多种屏幕尺寸和旋转

Eclipse Android:多种屏幕尺寸

Android:多种屏幕尺寸的多种翻译

仅需一种布局即可在Android中支持多种屏幕尺寸

配置更改屏幕尺寸和方向停止布局更改

将屏幕分为SurfaceView和xml布局

不同屏幕尺寸的android布局

android:屏幕尺寸布局更改

如何使布局适合屏幕尺寸

iOS Storyboard,布局在4.0英寸屏幕尺寸和3.5英寸屏幕尺寸之间尴尬地转换

适用于不同屏幕尺寸和不同密度的Android UI(布局+资源)

在不使用自动布局的情况下调整iPhone 5和iPhone 3.5'的屏幕尺寸

无论屏幕尺寸和方向如何,如何使Android布局成比例

根据屏幕尺寸自动布局进行设计

为所有屏幕尺寸创建布局

Android 上不同的屏幕尺寸布局

如何扩大android图形布局的屏幕尺寸?

不同的布局,适合不同的屏幕尺寸

android 约束布局支持不同的屏幕尺寸

在 Android 中为所有屏幕尺寸和所有屏幕密度创建布局的最佳实践是什么

屏幕密度和图像尺寸

如何将“自由形式” UIViewController 适合多种屏幕尺寸?

使用图像作为UIViewController的背景并支持多种屏幕尺寸

如何处理android多种尺寸的屏幕分辨率?

使用Handlebars和ExpressJS进行多种布局?

适用于iPhone 3.5英寸和iPhone 4英寸屏幕尺寸的自动布局设计

是否有必要为应用创建不同的屏幕尺寸和密度xml?最好的方法