3

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.

enter image description here

UPDATE:

enter image description here

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(), scheduleConcertsRelativeLayout.getHeight());
params.setMargins(0, timeline.getHeight(), 0, 0);
scheduleConcertsRelativeLayout.setLayoutParams(params);
simonbs
  • 7,932
  • 13
  • 69
  • 115

3 Answers3

1

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" ... \>
Laurent'
  • 2,611
  • 1
  • 14
  • 22
  • Yes, that gives me the same. But it's not really the scrollview which is the problem. It's the bottom relative layout in the scroll view which is the problem. – simonbs Oct 06 '11 at 12:59
  • Yep but your RelativeLayout parent is this HorizontalScrollView, hence the remark. Anyways, I'm as stuck as you here. – Laurent' Oct 06 '11 at 13:17
1

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);
simonbs
  • 7,932
  • 13
  • 69
  • 115
0

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

Caner
  • 57,267
  • 35
  • 174
  • 180
  • On the horizontal scrollview? Yes, that gives me the same. But it's not really the scrollview which is the problem. It's the bottom relative layout in the scroll view which is the problem. – simonbs Oct 06 '11 at 12:58
  • No, in `ScheduleRelativeLayout` ("horizontal scrollview" already extends to full width) – Caner Oct 06 '11 at 13:19
  • Please also try `android:layout_gravity="center_horizontal"` on `ScheduleRelativeLayout`. Do both changes at the same time. – Caner Oct 06 '11 at 13:28
  • That makes the scrollview begin on the middle, show the last half of it and then show blank space the rest half. – simonbs Oct 06 '11 at 13:37
  • One last try: `android:layout_gravity="RIGHT"` on `ScheduleRelativeLayout`, if this doesn't work then I don't know :( – Caner Oct 06 '11 at 14:02
  • That's the same, sadly. Though, I have found out that if I update the width and height of my `ScheduleConcertsRelativeLayout` after the layout has been laid, it is working. Check the original post. – simonbs Oct 06 '11 at 14:11