简体   繁体   中英

Android: How to make current layout with scrollable text view?

I tried multiple solution but none seem to work. Layout:

--------------------
|btn1|  txt1  |btn2|
--------------------
|                  |
|                  |
|                  |
|     txtview1     |
|                  |
|                  |
|                  |
--------------------

btn1 - top left aligned - decrease txt1
btn2 - top right aligned - increase txt1
txt1 - top center aligned - text/number entered with code
textview1 - client aligned with vertical scrollbar, if needed - text entered with code

Try 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">

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="btn1"/>

    <TextView
        android:id="@+id/txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="txt1"/>

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="btn2"/>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/btn1">

        <TextView
            android:id="@+id/txt2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="txt2"/>

    </ScrollView>

</RelativeLayout>

You should also align the second button to the right.
Your version places the second button over the first one...

Example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

    <Button android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="back"/>
    <TextView android:id="@+id/txt1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerHorizontal="true"
              android:text="txt1"/>
    <Button android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="btn2"/>

    <ScrollView android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_below="@id/button1">

        <TextView android:id="@+id/txt2"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_below="@id/button2"
                  android:text="txt2"/>
    </ScrollView>
</RelativeLayout>

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