我有一个垂直线性布局,它内部有两个具有不同元素的线性布局,我想将第一个固定在顶部,第二个居中,我正在尝试但不起作用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_bg"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#3b5998"
>
elements
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="300dip"
android:background="@drawable/background_resto"
android:gravity="center"
>
elements
</LinearLayout>
</LinearLayout
为什么它不起作用?提前谢谢你
最佳答案
我建议为此目的选择 RelativeLayout。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_bright"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:background="#fff" >
</LinearLayout>
<LinearLayout
android:layout_width="300dip"
android:layout_height="300dip"
android:layout_centerInParent="true"
android:background="@android:color/holo_green_light"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
这将帮助您设置相对于其他 View 的准确“相对”位置。
祝你好运, 蒂姆
关于android - 相对布局位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10750621/