简体   繁体   中英

Android Scroll view Image and text

I am solving a problem with image and text in one scroll view. The main problem is, that I get different image height from server side . But the place with image should be all the time same. Now the height of image place is dynamic. The text should be scrollable with the image.

Is there any possibility how to make the image height static?

Thank you!

在此处输入图片说明

EDIT

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

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

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

        <RelativeLayout
            android:id="@+id/article_gallery"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="4" >

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

                <ImageView
                    android:id="@+id/article_image_back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:src="@drawable/sipka_l" />

                <ImageView
                    android:id="@+id/article_image"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1" />

                <ImageView
                    android:id="@+id/article_image_next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:src="@drawable/sipka_p" />
            </LinearLayout>

            <TextView
                android:id="@+id/image_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/tran_dark_gray"
                android:gravity="center"
                android:padding="@dimen/size_8"
                android:textAppearance="@style/xsmallLight" />
        </RelativeLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="6"
            android:background="@color/opaq_light"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="@dimen/size_16" >

                <TextView
                    android:id="@+id/article_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingBottom="@dimen/size_12"
                    android:textAppearance="@style/normalBold" />

                <TextView
                    android:id="@+id/article_body"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/xsmall" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
</FrameLayout>

If you declare the ImageView with a fixed width and height it will remain static all the time.

Try something like:

 <ImageView
        android:id="@+id/imageView1"
        android:layout_width="50dp"
        android:layout_height="50dp"
/>

Put this ImageView inside a ScrollView and ofcourse put your TextView inside the same ScrollView.

you can use layout weights for your linearlayout. Set the width to 0 and let the weight determine actual size. Setting weight to 0.33 each gives each images 1/3 of the screen. Or you could set one to 0.5 and the others to 0.25 each or whatever makes sense for your app.

Set the 3 images as:

      <ImageView
           android:id="@+id/article_image_back"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="0.33"
           android:layout_gravity="center_vertical"
           android:src="@drawable/sipka_l" />

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