-1

我有一个RelativeLayout样式为 aButtonBar并包含在 a 中HorizontalScrollView,这个布局被分配到一个固定的高度以便被控制,但这使它在小屏幕设备中看起来很大,

例如,在10'设备中:

在此处输入图像描述

3.7'设备中:

在此处输入图像描述

这是我的XML代码:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tool"
    android:id="@+id/horizontalScrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >
    <RelativeLayout
        android:id= "@+id/buttobbar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:gravity="top"
        style="@android:style/ButtonBar"
        android:background="@drawable/released" >

        <Button
            android:id="@+id/Main"
            android:layout_width="120dp"
            android:layout_height="60dp"
            android:background="@android:color/transparent"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            android:text="@string/main"/>

        <View 
            android:id="@+id/separator"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@+id/Main"
            android:layout_width="1px"
            android:background="@drawable/separators"/>

        <Button
            android:id="@+id/HomeView"
            android:layout_width="120dp"
            android:layout_height="60dp"
            android:background="@android:color/transparent"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            android:layout_toRightOf="@+id/Main"
            android:text="@string/homeview" />

         <View 
            android:id="@+id/separator"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@+id/HomeView"
            android:layout_width="1px"
            android:background="@drawable/separators"/>

          .
          .
          . <!-- after 7 other buttons separated with views --!>
    </RelativeLayout>
    </HorizontalScrollView>
4

3 回答 3

1

在相对布局的地方采用线性布局,你不必给出 layout_width 的绝对值,只需使用 android:layout_weight 并为此赋予所有按钮权重它会在所有屏幕上自动调整,无论它是什么我认为它会帮助你

于 2013-11-27T09:52:49.287 回答
0

增加重量是最好的选择:试试这个:

android:weightSum="1"

并将这个重量总和除以按钮如下:

android:layout_weight=0.5
于 2014-03-26T11:01:37.983 回答
0

只需编写以下代码即可为布局(线性布局)分配权重:

 android:weightSum="1"(can vary,according to your requirement)

并将这个重量总和除以按钮如下:

android:layout_weight=0.5

于 2013-11-27T10:00:22.963 回答