我有一個非常簡單的布局,我不能讓它看起來像我想要的。它是一個帶有按鈕和開關的LinearLayout。我希望他們顯示一個在另一個之上,但我想要他們的寬度是父布局的一半。
|--LinearLayout---------|
| |
| ----------- |
|| Switch | |
| ----------- |
| ----------- |
|| button | |
| ----------- |
------------------------
我一直在尋找其他類似的答案在SO,但我找不到一個解決方案,為我工作。這是我到目前為止所嘗試的:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2" >
android:id="@+id/remember_me_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/remember" />
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" />
這樣,按鈕和開關占據父節點的所有空間,而不是隻占據一半。
我試過在android:layout_width = 0dp在孩子,但它使它們消失。
有什麼幫助嗎?