Android-Layout funktioniert nicht richtig
-
29-10-2019 - |
Frage
Ich verwende die Datei main.xml
, um die Benutzeroberfläche in Android zu entwerfen.Ich weiß nicht, warum der letzte TextView
(id: ImageDescription) nicht funktioniert.Wenn ich das ImageView
-Tag lösche, funktioniert der letzte TextView
wieder.
Hier ist mein Screenshot.das erste, wenn kein ImageView
-Tag vorhanden ist, und das zweite, wenn ImageView
vorhanden ist
Wie Sie sehen, kann ich bei generiertem Bild keinen ZeilenImage descriptor: a cartoon tiger
sehen.
Hier ist mein 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>
Danke für die Hilfe :)
Lösung
Sie fügen Ihre imageDescription-Textansicht unterhalb der Bildansicht hinzu, und auch Ihre Bildlaufansicht hat mit und Höhe als fill_parent. Versuchen Sie dies einmal
<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"/>
Ich denke, das Bild ist zu groß. Wenn dies der Fall ist, geben Sie den layout:weight
-Parameter für die Bild- und Textansicht in angemessenem Prozentsatz an.
Andere Tipps
Versuchen Sie, Ihren XML-Teil zu ändern
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
bis
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
weil Ihr ScrollView
versucht, in der Höhe so groß wie Ihr LinearLayout
zu sein.
Ich habe eine andere Antwort auf meine Frage. Ich poste hier, an wen ich meinen Beitrag angesehen habe und weitere Antworten benötige.Dass ich android:adjustViewBounds="true"
Property verwende :)