1

I'm using file main.xml to design UI in Android. I don't know why the last TextView (id: ImageDescription) doesn't work. If I delete ImageView tag, the last TextView will work again. Here is my screenshot. the first in when no ImageView tag, and the second when has ImageView

not <code>ImageView</code> tag with <code>ImageView</code> tag

As you see, when has image, I cannot see line Image descriptor: a cartoon tiger. Here is my main.xml:

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/imageTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/test_image_title"/>

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


     <ImageView
         android:id="@+id/imageDisplay"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:contentDescription="@string/test_contentDescription"
         android:src="@drawable/test_image"/>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView 
            android:id="@+id/imageDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/test_image_description"/>
    </ScrollView>         

</LinearLayout>

thanks for help me :)

hqt
  • 29,632
  • 51
  • 171
  • 250
  • from ScrollView documentation `The TextView class also takes care of its own scrolling, so does not require a ScrollView` – Selvin Feb 22 '12 at 15:30
  • 2
    @Selvin Yes. I think the problem is not `ScrollView` because when I delete `ScrollView` tag, still nothing happen different :( – hqt Feb 22 '12 at 15:44
  • 2
    it's pretty simple and obvious ... image is too big ... it seems to have black bar at the top and bottom ... maybe you should put both image and desription to another linearlayout and then put this linearlayout to scrollview ... – Selvin Feb 22 '12 at 15:48

3 Answers3

1

You are adding your imageDescription textview below imageview and that too your scrollview has both with and hight as fill_parent, once try this

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


    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView 
            android:id="@+id/imageDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/test_image_description"/>
    </ScrollView> 

     <ImageView
         android:id="@+id/imageDisplay"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:contentDescription="@string/test_contentDescription"
         android:src="@drawable/test_image"/>

I think image is too big, if it's the case try by specifying layout:weight parameter for both image and text view in proper percentage.

Sankar
  • 1,685
  • 2
  • 16
  • 27
  • 1
    Yes. your code work, but that not UI I want. I want image description at below. Can I do it ? – hqt Feb 22 '12 at 15:28
  • then, only change the width and height of your scrollview as in my post why because it's trying to occupy total parent size. – Sankar Feb 22 '12 at 15:48
  • 1
    I think image is too big, if it's the case try by specifying layout:weight parameter for both image and text view in proper percentage. – Sankar Feb 22 '12 at 15:57
  • Oh. I don't see you add `layout:weight` to your original post :) thanks :) – hqt Feb 23 '12 at 13:09
1

Try to change your XML part

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

to

<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

because your ScrollView tries to be as big as your LinearLayout in height.

IBoS
  • 550
  • 5
  • 15
  • 1
    Also you didn't have any margin or padding in your XML for your ImageView but it's way under your TextViews. Doesn't your testimage have black or transparent stripes at the top and bottom pushing the ScrollView out of the viewable area? – IBoS Feb 22 '12 at 15:55
  • 2
    yes. maybe my image has transparent tripes, but when I make this as wallpaper, I don't see transparent tripes on both up and down side. How can test it, do you know please teach me :) – hqt Feb 22 '12 at 16:29
  • Well, which is easier for you: 1: Check the image on your favourite image manipulator on PC. 2: Try setting width and/or height of the ImageView to some static values like "20sp" or "30dp" 3: Try another image and don't forget to use "wrap_content" – IBoS Feb 22 '12 at 16:52
1

I have another answer for my question, I post here to whom have viewed my post and need more answers. That I use android:adjustViewBounds="true" Property :)

hqt
  • 29,632
  • 51
  • 171
  • 250