【问题标题】:Android: How to make current layout with scrollable text view?Android:如何使用可滚动的文本视图制作当前布局?
【发布时间】:2011-02-06 23:37:45
【问题描述】:

我尝试了多种解决方案,但似乎都没有奏效。布局:

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

btn1 - 左上对齐 - 减少 txt1
btn2 - 右上角对齐 - 增加 txt1
txt1 - 顶部居中对齐 - 使用代码输入的文本/数字
textview1 - 客户端与垂直滚动条对齐,如果需要 - 使用代码输入的文本

【问题讨论】:

    标签: android layout button scroll textview


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 很好,但是txt2现在也超过了btn1、txt2和btn2。它应该在他们之下。
    • ups,忽略了 android:layout_below="@id/btn1"。
    【解决方案2】:

    您还应该将第二个按钮向右对齐。
    您的版本将第二个按钮放在第一个按钮上...

    示例:

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

    【讨论】:

    • 如果您想在答案中包含代码,请在每行代码前放置 4 个空格。谢谢!查看更多信息in this page
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多