Jib*_*ibW 2 android android-layout
我只需要在屏幕上平行放置两个按钮(每个宽度为50dp).第一个应该留有10dp的边距并且放置就好了.
但是第二个按钮应该放在屏幕上,保持从中间(水平)留下30dp马林.我需要做的是它应该从我用箭头指示的地方开始.

我的设计xml如下.使用LinearLayout或RelativeLayout无关紧要.
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#634785" >
<Button
android:id="@+id/button1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="B1"
android:layout_marginLeft="10dp" />
<Button
android:id="@+id/button2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="B2"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在容器的中心放置一个不可见的视图(0dp宽和高),并根据需要将第二个按钮相对于它对齐:
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#634785" >
<Button
android:id="@+id/button1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="B1"
android:layout_marginLeft="10dp"
/>
<Button
android:id="@+id/container_center"
android:layout_centerInParent="true"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<Button
android:id="@+id/button2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="B2"
android:layout_toRightOf="@+id/container_center"
android:layout_marginLeft="30dp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3241 次 |
| 最近记录: |