解決策がテキストビューにlayout_weight = "1"を追加している類似の質問がたくさんあります。私はそれを試みたが、それは私を助けなかった。私のシナリオは異なります。それが重複しているとは考えないでください。LinearLayoutのTextViewがラップしてImageViewに移動しない
以下は私が作りたいレイアウトです。イメージビューにイメージがある場合、TextViewはラップする必要があります。画像がない場合はそのままでなければなりません。以下は
私がこれまでに以下
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_alignParentStart="true"
android:gravity="start|center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text here"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text here which should wrap depending upon
the string length and also considering whether or not there is an image adjacent to it"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text here"/>
</LinearLayout>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:adjustViewBounds="true"
android:src="@drawable/save"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
を試したコードは、このコードの結果です。 TextViewはラッピングなしでImageViewの下にあります。
間違って私のアプローチです。誰かが私にこれを解決する手助けをすることができます私は、mini APIレベル21で開発しているAndroidStudio 3.0を使用しています(これはすべて重要です)。 ありがとうございます
感謝。それは働いている。しかし、あなたはこのことを説明できますか?なぜこのようなことが起き、layout_weight – Krishna
の水平線形レイアウトの魔法は、2つの子供と1つの垂直線形レイアウトと別の画像を持っています。垂直線形レイアウトをweight:1に設定します。これは、imageviewにウェイトがないため、常に100%のスペースを取ることを意味します。画像が利用可能なときは、画像空間を除く100%の空間が必要となり、画像が利用できないときは画像なしで親の100%の空間が必要になります。 – Yeahia2508