开发者

Relative Layout fill_parent issue

First of all, I am new to Android development so this might be a simple issue but I really can't get it working.

I have the following layout.

<?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>

What you see is that I have a horizontal scrollview (ScheduleScrollView) which has two relative layouts. The upper one contains a timeline (ScheduleTimelineRelativeLayout) while the lower one (ScheduleConcertsRelativeLayout) will contain some buttons created programmatically. The horizontal scrollview is as wide as the timeline. I would like the lower relative layout to fill it's parent, meaning that it should be as wide as the horizontal scrollview but this doesn't work.

I have searched this forum trying to find an answer to my question. Some suggests using android:layout_width="match_parent" but when doing so, I will get the following error:

Error: String types not allowed (at 'layout_width' with value 'match_parent')

Others suggests setting android:layout_weight="1" but this changes nothing (and the setting is not available in my autocomplete so it seems that it doesn't exist)

The screenshot below shows my issue. The green part is the background color of my horizontal scrollview. This should not be visible. Instead the lower red part should go to the edge.

Relative Layout fill_parent issue

UPDATE:

Relative Layout fill_parent issue

UPDATE:

Setting the width and height of ScheduleConcertsRelativeLayout programatically after the layout has been laid is working.

RelativeLayout timeline = (RelativeLayout) findViewById(R.id.ScheduleTimelineRelativeLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(timeline.getWidth(), scheduleCo开发者_如何学PythonncertsRelativeLayout.getHeight());
params.setMargins(0, timeline.getHeight(), 0, 0);
scheduleConcertsRelativeLayout.setLayoutParams(params);


I'm probably missing something here, but did you try to change:

<HorizontalScrollView android:id="@+id/ScheduleScrollView" android:layout_width="wrap_content" ... \>

to

<HorizontalScrollView android:id="@+id/ScheduleScrollView" android:layout_width="fill_parent" ... \>


Setting the width and height of ScheduleConcertsRelativeLayout programatically after the layout has been laid is working.

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);


Did you try android:layout_width="fill_parent" on ScheduleRelativeLayout?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜