我有一个非常简单的布局,我不能让它看起来像我想要的。它是一个带有按钮和开关的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在孩子,但它使它们消失。
有什么帮助吗?