简体   繁体   中英

Scroll View hides my relative layout1

I am new to Android and I need some help. I have an image, scrollable text and buttons below text in my layout, but the scrollview hides the relative layout where the buttons are. I tried linear layout to, but the problem remains. Here is my code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:contentDescription="@string/houseofstark"
    android:scaleType="centerCrop"
    android:src="@drawable/coverart" />

<ScrollView
    android:id="@+id/scrolly"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/imageView1"
    android:paddingTop="8dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/lyrics"
        android:paddingBottom="8dp"
        android:text="@string/lyrics"
        android:textAlignment="gravity"
        android:textSize="18sp" />
</ScrollView>

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/scrolly" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="8dp"
        android:background="#444444"
        android:onClick="openwp"
        android:text="@string/hbowebpage"
        android:textColor="#f9f5f5"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/button1"
        android:background="#3b5998"
        android:onClick="openFB"
        android:text="@string/facebookpage"
        android:textColor="#ffffff"
        android:textStyle="bold" />
</RelativeLayout>

I suspect the problem is that the ScrollView has a android:layout_height="wrap_content" attribute. Which makes no sense, given that the purpose of a scroll view is to have content with varying size. And this ends up with the scroll view taking more space than you expect and pushing the buttons down below the screen.

Try giving the scroll view a gravity value and a height of 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM