Ich habe eine Nachrichtenaktivität mit ImageView
und TextView
mit Nachrichteninhalt. Ich möchte, dass Nachrichteninhalte den gesamten Raum ausfüllen.Android-Make TextView, um den gesamten verbleibenden Platz im Layout zu füllen
Der Nachrichteninhalt füllte den ganzen Raum rechts von der Bildansicht, so dass der Text rechts vom Bild platziert wurde, aber unter dem Bild war es freier Platz. Ich entschied mich, die ImageView
und TextView
in getrennten linearen Layout zu setzen. Aber der Text verschwand, nachdem der Bereich direkt aus dem Bild gefüllt wurde.
Das Problem wird angezeigt here.
Meine Fragen sind:
Wie ich den restlichen Text unter dem Bild Ansicht platzieren können?
Wie kann ich das Bild machen, um sein Verhältnis Höhe/Breite zu behalten?
Hier ist der XML-Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tutorialsbuzz.phrasebook.NewsActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewHeaderNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewDateNews"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="header"
android:textColor="@color/mycolor"
android:textSize="16dp"
android:textStyle="bold|italic" />
<LinearLayout
android:id="@+id/newslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewHeaderNews"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewNews"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_margin="2dp"
android:layout_weight="0"
android:scaleType="fitXY"
android:src="@drawable/world"/>
<TextView
android:id="@+id/textViewContentNews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="1dp"
android:layout_weight="1"
android:text="jklasdf as ;AJFWADLHF LAS HFLAF VANLASN: l galgsalgngan ;wafasldwlaf alla lnaf alf lg;aeguewaf hwla hfnalgh wa
j;fklasgj;s;nva; alsf las ps z; laszfj alsz vzlxg a lrg z;dnlxfdj glzf ;f glaerzlls az
;asdjk aF{ af[ [D{j as ;as ; wjv a jkn da weq g ; aeskj; g ;eakr;ja r"
android:textSize="14dp" />
</LinearLayout>
<TextView
android:id="@+id/textViewDateNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:text="date"
android:textSize="14dp" />
<TextView
android:id="@+id/textViewViewsNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/newslayout"
android:layout_margin="3dp"
android:text="views"
android:textSize="13dp" />
<TextView
android:id="@+id/textViewRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/newslayout"
android:layout_margin="3dp"
android:text="rating"
android:textSize="13dp" />
<TextView
android:id="@+id/textViewRatingNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/spinnerRatingNews"
android:layout_margin="4dp"
android:layout_toLeftOf="@+id/spinnerRatingNews"
android:text="Գնահատեք."
android:textSize="14dp" />
<Spinner
android:id="@+id/spinnerRatingNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textViewRating"
android:layout_margin="3dp" />
</RelativeLayout>
</ScrollView>
Vielen Dank. Und wie kann ImageView sein Verhältnis Höhe/Breite beibehalten? –
Nun, Sie haben seine Höhe/Breite fest codiert, so dass Sie sein ursprüngliches Höhe/Breite-Verhältnis nicht beibehalten können. Sie können stattdessen wrap_content verwenden. –
Aber ich brauche verschiedene Bilder für verschiedene Nachrichten, mit unterschiedlicher Höhe und Breite. Also muss ich sie in meinem ImageView platzieren und ihre Ansicht behalten. –