Android-layout does not work properly
-
29-10-2019 - |
문제
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
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 :)
해결책
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.
다른 팁
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.
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 :)