【发布时间】:2011-06-15 07:49:55
【问题描述】:
我正在尝试将 RelativeLayout 放在嵌套在另一个 LinearLayout 中的 LinearLayout 下方,但它不起作用。
有什么办法可以做到吗?
我需要保留设置权重的能力以及将布局(带有一些透明背景)放置在另一个布局之上的能力。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relative"
android:layout_width="wrap_content" android:layout_height="fill_parent" >
<LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_horizontal" android:orientation="vertical" android:weightSum="800">
<LinearLayout android:layout_alignParentRight="true" android:layout_width="fill_parent" android:id="@+id/infoCanso" android:orientation="vertical" android:background="@drawable/black_glossy_bg_iphone" android:gravity="center_vertical|center_horizontal" android:layout_height="0dip" android:layout_weight="90">
</LinearLayout>
<LinearLayout android:id="@+id/albumBG" android:layout_width="wrap_content" android:layout_below="@+id/infoCanso" android:layout_height="0dip" android:layout_weight="482">
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout1" android:background="#80ffffff" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="90">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="0dip" android:id="@+id/LinearLayout01" android:layout_weight="100" android:background="#ffffff">
</LinearLayout>
</LinearLayout>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="50dip" android:id="@+id/volumeBar" android:background="#80000000" android:gravity="center" android:layout_below="@+id/infoCanso">
</RelativeLayout>
</RelativeLayout>
【问题讨论】:
-
不要尝试在你的 xml 上使用尽可能多的布局,这不是一个好的设计,如果你想要这样的设计意味着尝试通过使用 android:layout_below 属性来使用 RelativeLayout 本身来获取所需的视图。
-
我已经使用RelativeLayouts 完成了,但我需要使用LinearLayouts 的layout_weight 属性。为什么使用LinearLayouts 不好?
-
您是否收到任何错误或未按您的预期工作?
-
没有错误,这不是我预期的工作。
标签: android android-layout android-linearlayout android-relativelayout