У меня очень простой макет, который я не могу сделать так, как будто хочу. Это LinearLayout с кнопкой и переключателем. Я хочу, чтобы они показывали один над другим, но я хочу, чтобы их ширина была половиной родительского макета.
|--LinearLayout---------|
| |
| ----------- |
|| Switch | |
| ----------- |
| ----------- |
|| button | |
| ----------- |
------------------------
Я смотрел на другой подобный ответ в SO, но я не мог найти решение, которое работает для меня. Это то, что я пробовал до сих пор:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2" >
<Switch
android:id="@+id/remember_me_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/remember" />
<Button
android:id="@+id/share_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="loginOnclick"
android:text="@string/login_button_text" />
</LinearLayout>
При этом кнопка и коммутатор занимают все пространство родителя вместо того, чтобы брать только половину.
Я пробовал с android:layout_width = 0dp
у детей, но он заставляет их исчезать.
Любая помощь, пожалуйста?