我的主页上有两个主要的布局。第一个是RelativeLayout(ID为“tabView”),第二个是LinearLayout(ID为“menuView”)。这两个布局都存在于一个RelativeLayout内(ID为“parentView”)。默认情况下,tabView具有parentView的高度和宽度,而menuView具有parentView的高度,但width设置为0dp。我希望menuView向右滑动,使其宽度等于parentView的20%,而tabView的宽度应该更改为容纳的parentView的80%。但是,根据我的代码,测量结果没有变化。我做错了什么?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Home" >
<LinearLayout
android:id="@+id/menuView"
android:layout_alignParentLeft="true"
android:layout_height="match_parent"
android:layout_width="0dp"
android:orientation="horizontal">
</LinearLayout>
<RelativeLayout
android:id="@+id/tabhostcontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true">
LinearLayout menuView = (LinearLayout) findViewById(R.id.menuView);
RelativeLayout parentView = (RelativeLayout) findViewById(R.id.parentView);
RelativeLayout tabView = (RelativeLayout) findViewById(R.id.tabhostcontainer);
Log.v(tabViewTag, Integer.toString(tabView.getWidth()));
Log.v(parentViewTag, Integer.toString(parentView.getWidth()));
menuView.setLayoutParams(new RelativeLayout.LayoutParams((int) (parentView.getWidth()*.2), menuView.getHeight()));
tabView.setLayoutParams(new RelativeLayout.LayoutParams((int) (parentView.getWidth()*.8), tabView.getHeight()));
答案 0 :(得分:0)
将menuView的权重设置为1,将tabsView的权重设置为4 ..它将创建1:4的比例,即20%-80% 将两个布局的宽度设置为0dp