问题
I read all the relative layout questions already posted and I guess I'm note double asking, sorry if I am.
I'm trying to stick an image in the bottom of my app, and above is I have a scrollview, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/RelativeLayout1">
<ScrollView android:paddingTop="180dip" android:layout_width="fill_parent" android:id="@+id/scrollView12" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linearLayout4" android:layout_width="fill_parent" android:paddingRight="8dip" android:orientation="vertical" android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
<ImageView android:layout_width="fill_parent"
android:background="@color/cinza" android:src="@drawable/header"
android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_alignParentBottom="true">
</ImageView>
</RelativeLayout>
I feed the scrollview dinamically, so the size of it can change. My problem is that if it grows till the end of the display, the last records goes behind my picture. I wanted it to grow just untill the picture. Some clue on how to do this? I tried several ways, relativelayouts, linearlayouts, but sometimes the picture disappears, sometimes don't stick in the bottom... Hope my question was clear.
Thanks in advance,
João
回答1:
You should just add android:layout_above="@+id/imageView2"
for the ScrollView, and define the ImageView first, as you want it to be draw first, then the ScrollView inside the RelativeLayout
.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/RelativeLayout1">
<ImageView
android:layout_width="fill_parent"
android:background="@color/cinza"
android:src="@drawable/header"
android:id="@+id/imageView2"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
</ImageView>
<ScrollView
android:paddingTop="180dip"
android:layout_width="fill_parent"
android:id="@+id/scrollView12"
android:layout_above="@+id/imageView2"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:paddingRight="8dip"
android:orientation="vertical"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
</RelativeLayout>
回答2:
RelativeLayout
is not the right chose in this case. You have to use LinearLayout
, and the key is the android:layout_weight
parameter:
<?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">
<ScrollView android:paddingTop="180dip"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:paddingRight="8dip"
android:orientation="vertical"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
<ImageView android:layout_width="fill_parent"
android:background="@color/cinza"
android:src="@drawable/header"
android:id="@+id/imageView2"
android:layout_height="wrap_content" />
回答3:
Give a id for scroolview then set a tag in image view android:layout_blow="id of scrollview"
i hope this is answer.
来源:https://stackoverflow.com/questions/7442911/relativelayout-issue-image-overlaps-scrollview