Невозможно установить вес кнопок внутри прокрутки - PullRequest
0 голосов
/ 23 июля 2011

Я пытаюсь установить набор кнопок внутри ScrollView равным весу. Я попытался использовать следующий код, но он не работает. У кого-нибудь есть идеи, как установить одинаковый вес кнопок?

<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
    <Button android:id="@+id/b1" android:text="@string/s1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:id="@+id/b2" android:text="@string/s2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <HorizontalScrollView android:id="@+id/HorizontalScrollView1" android:layout_height="fill_parent"  android:fillViewport="true" android:layout_width="wrap_content">
        <LinearLayout android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:layout_width="wrap_content">
            <Button android:id="@+id/bShortcut1" android:text="Button" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1"></Button>
            <Button android:id="@+id/bShortcut2" android:text="Button" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1"></Button>
            <Button android:text="Button" android:id="@+id/bShortcut3" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="0dp"></Button>
            <Button android:text="Button" android:layout_height="wrap_content" android:id="@+id/bShortcut31" android:layout_width="0dp" android:layout_weight="1"></Button>
            <Button android:id="@+id/bShortcut4" android:text="Button" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"></Button>
            <Button android:id="@+id/bShortcut5" android:text="Button" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"></Button>
            <Button android:id="@+id/bShortcut6" android:text="Button" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"></Button>

        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout> 

Ответы [ 2 ]

1 голос
/ 23 июля 2011

Это точно не сработает.

  • На самом деле то, что вы сделали, это то, что вы присвоили вес 1 каждой кнопке.Теперь это означает, что фактическая ширина родительского элемента, т. Е. Линейная компоновка в вашем случае, будет равномерно распределена между всеми кнопками.

  • И вы также установили атрибут android:layout_width="wrap_content "для линейного макета. Это означает, что его ширина будет фактически равна сумме ширин всех кнопок.

это означает, что оба ваших макета взаимозависимы друг от друга.

0 голосов
/ 23 июля 2011

С какой реальной проблемой вы сталкиваетесь?Вы вообще видите кнопки?

Я бы сказал, замените android: layout_width = "0dp" на wrap_content и попробуйте снова.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...