[英]Relative Layout fill_parent issue
首先,我是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
)將包含一些以編程方式創建的按鈕。 水平滾動視圖與時間軸一樣寬。 我希望較低的相對布局填充它的父級,這意味着它應該與水平scrollview一樣寬,但這不起作用。
我搜索了這個論壇試圖找到我的問題的答案。 有人建議使用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);
我可能在這里遺漏了一些東西,但你是否試圖改變:
<HorizontalScrollView android:id="@+id/ScheduleScrollView" android:layout_width="wrap_content" ... \>
至
<HorizontalScrollView android:id="@+id/ScheduleScrollView" android:layout_width="fill_parent" ... \>
在布局布局之后以編程方式設置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);
你在ScheduleRelativeLayout
上嘗試了android:layout_width="fill_parent"
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.