【问题标题】:Working with ScrollView and TextView使用 ScrollView 和 TextView
【发布时间】:2014-04-01 15:48:39
【问题描述】:

我有一个 android 活动,它在同一活动上有一个 ImageView 和一个 TextView。 但是,文本的长度超过了屏幕,因此我希望它可以滚动而不滚动顶部的图像。

这是我尝试过的,但无法达到我想要的效果。

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="260dp"
    android:layout_height="210dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginRight="0dp"
    android:layout_marginStart="0dp"
    android:layout_marginTop="0dp"
    android:src="@drawable/xdr" />

<ScrollView>
    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_alignParentBottom="true"
    android:text="@string/xdr" />
</ScrollView>

我的想法是,将TextView 放入ScrollView 可以使文本滚动,同时保留图像,这在ScrollView 之外完好无损,但似乎我错了。

请问怎样才能达到我想要的效果?

【问题讨论】:

  • 使用权重属性
  • 我建议你发布完整的布局,因为这个,不仅不编译,而且缺乏关键属性。

标签: android layout textview scrollview


【解决方案1】:

在xml下面使用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="260dp"
            android:layout_height="210dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="0dp"
            android:src="@drawable/xdr" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView1" >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/xdr" />


    </LinearLayout>

    </ScrollView>

</RelativeLayout>

【讨论】:

    【解决方案2】:

    我更改了滚动视图属性。使用这个 xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="260dp"
            android:layout_height="210dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="0dp"
            android:src="@drawable/xdr" />
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/imageView1"
            android:layout_alignParentBottom="true" >
    
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/xdr"
                ></TextView>
        </ScrollView>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 2018-02-19
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多