Ширина элементов по активности не права? - PullRequest
0 голосов
/ 19 декабря 2011

У меня макет моего приложения установлен на 480dpi в ширину, а 480/4 - на 120. Итак, если у меня 4 кнопки в верхней части приложения и я установил одну на 120dpi в ширину, почему кнопка занимает половина экрана ?! Как я могу получить кнопки для равномерного размера в верхней части?

Здесь я только что добавил 4 кнопки вверху:

Тогда первые две кнопки имеют ширину 120 точек на дюйм:

Ответы [ 3 ]

2 голосов
/ 19 декабря 2011

проверить это:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </Button>
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </Button>
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </Button>
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </Button>
    </LinearLayout>
1 голос
/ 19 декабря 2011

Вы можете использовать параметр FILL_PARENT для ширины макета и добавить вес 1 к каждой из ваших кнопок, чтобы получить желаемый эффект

0 голосов
/ 19 декабря 2011

Попробуйте это

<TableRow android:layout_width="fill_parent"
    android:weightSum="100" android:layout_height="wrap_content">
    <Button android:text="Button" android:layout_weight="25"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:layout_width="wrap_content"
        android:layout_weight="25" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:layout_weight="25"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:layout_weight="25"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
...