首先,我是 Android 开发的新手,所以这可能是一个简单的问题,但我真的无法让它工作。
我有以下布局。
<?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"
android:weightSum="1">
<FrameLayout android:id="@+id/navigationBarFrameLayout"
android:layout_width="fill_parent"
android:layout_height="44dp">
<ImageView android:id="@+id/navigationBar"
android:src="@drawable/navigationbar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"/>
<TextView android:text="TextView"
android:layout_width="fill_parent"
android:id="@+id/navigationBarTitle"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:textColor="#000"
android:textSize="24sp"
android:textStyle="bold"
android:shadowColor="#fff"
android:shadowDy="-1"
android:shadowDx="0"
android:shadowRadius="1"/>
</FrameLayout>
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:id="@+id/DayPager"
android:layout_height="82dp">
</android.support.v4.view.ViewPager>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/relativeLayout">
<HorizontalScrollView android:id="@+id/ScheduleScrollView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:layout_above="@+id/tabBarFrameLayout"
android:scrollbars="none"
android:background="#00ff00">
<RelativeLayout android:id="@+id/ScheduleRelativeLayout"
android:layout_height="fill_parent"
android:layout_width="wrap_content">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ScheduleTimelineRelativeLayout">
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ScheduleConcertsRelativeLayout"
android:layout_below="@+id/ScheduleTimelineRelativeLayout"
android:background="#ff0000"
android:layout_weight="1">
</RelativeLayout>
</RelativeLayout>
</HorizontalScrollView>
<FrameLayout android:id="@+id/tabBarFrameLayout"
android:layout_height="49dp"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
<ImageView android:id="@+id/imageView1"
android:src="@drawable/tabbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"/>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
你看到的是我有一个水平滚动视图(ScheduleScrollView
),它有两个相对布局。上一个包含时间线 ( ScheduleTimelineRelativeLayout
),而下一个 ( ScheduleConcertsRelativeLayout
) 将包含一些以编程方式创建的按钮。水平滚动视图与时间线一样宽。我希望较低的相对布局填充它的父级,这意味着它应该与水平滚动视图一样宽,但这不起作用。
我搜索了这个论坛,试图找到我的问题的答案。有人建议使用android:layout_width="match_parent"
,但这样做时,我会收到以下错误:
错误:不允许字符串类型(在“layout_width”处,值为“match_parent”)
其他人建议设置android:layout_weight="1"
,但这没有任何改变(并且该设置在我的自动完成中不可用,因此它似乎不存在)
下面的屏幕截图显示了我的问题。绿色部分是我的水平滚动视图的背景颜色。这不应该是可见的。相反,较低的红色部分应该到边缘。
更新:
更新:
ScheduleConcertsRelativeLayout
在布局布局后以编程方式设置宽度和高度是有效的。
RelativeLayout timeline = (RelativeLayout) findViewById(R.id.ScheduleTimelineRelativeLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(timeline.getWidth(), scheduleConcertsRelativeLayout.getHeight());
params.setMargins(0, timeline.getHeight(), 0, 0);
scheduleConcertsRelativeLayout.setLayoutParams(params);