在Imageview后面的Textview滚动

时间:2013-12-23 10:45:49

标签: android android-layout scroll

在我的应用程序中,我想在ImageView上滚动TextView,但在我的XML Design中,ImageView后面的TextView滚动,如何在ImageView上滚动TextView,请给我解决方案。

这是我的XML代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"`enter code here`
android:layout_height="match_parent"
android:orientation="vertical" >

    <FrameLayout 
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:id="@+id/img" 
            android:layout_width="match_parent"
            android:layout_height="match_parent">


         <ImageView
                   android:id="@+id/article_image"
                   android:layout_width="match_parent"
                   android:layout_height="250dp"
                   android:layout_gravity="top"
                   android:scaleType="fitXY"
                   android:src="@drawable/garden"/>

             <TextView
                   android:id="@+id/image_desc"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:background="#77000000"
                   android:gravity="center|bottom"
                   android:padding="8dp"/>

      </RelativeLayout>  
   </FrameLayout>  

    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/frame">

             <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#77000000">


            <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="16dp" >

            <TextView
                    android:id="@+id/article_body"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#ffffff"
                    android:text="A good practice to bring the best performance 
                    for android application is to make sure your main thread does 
                    the minimum amount of work. Any long running tasks or heavy 
                    operations are usually performed in a different thread. 
                    Typical long running tasks could be network operations, 
                    reading files form memory, animations, etc. In this article, 
                    we will create a simple asynchronous ListView in Android. 
                    ListView with thumbnails thumbnails on each row 
                    (as shows in the image below) will be loaded asynchronously 
                    form server. We will populate a ListView with thumbnail images 
                    downloaded from the internet using a AsyncTask.A good practice to bring the best performance 
                    for android application is to make sure your main thread does 
                    the minimum amount of work. Any long running tasks or heavy 
                    operations are usually performed in a different thread. 
                    Typical long running tasks could be network operations, 
                    reading files form memory, animations, etc. In this article, 
                    we will create a simple asynchronous ListView in Android. 
                    ListView with thumbnails thumbnails on each row 
                    (as shows in the image below) will be loaded asynchronously 
                    form server. We will populate a ListView with thumbnail images 
                    downloaded from the internet using a AsyncTask." />

            </RelativeLayout>
        </ScrollView>
        </RelativeLayout>
   </RelativeLayout>

enter image description here enter image description here

3 个答案:

答案 0 :(得分:2)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <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:layout_marginTop="100dp"
                android:text="@string/hello_world" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

答案 1 :(得分:2)

<FrameLayout 
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">




     <ImageView
               android:id="@+id/article_image"
               android:layout_width="match_parent"
               android:layout_height="250dp"
               android:layout_gravity="top"
               android:scaleType="fitXY"
               android:src="@drawable/garden"/>

      <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

    <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:layout_marginTop="100dp"
            android:text="@string/hello_world" />
    </LinearLayout>
</ScrollView>
  </FrameLayout >  

这样做我希望这是有效的..我有同样的问题并通过使用它来解决。

答案 2 :(得分:0)

在这种情况下,请尝试使用Relative Layout而不是Frame Layout,因为它提供了更多功能,并且更有可能处理视图在其中的位置。这种情况的实现几乎是相同的,只是先放置Image View,然后放置本例的其余视图。