私はAndroidに動的に追加された長い文字列を持つフラグメントを作成しています。行数は可変です。私はLinearLayoutを使って画像の下にテキストを格納しています。私はテキストの下に画像の幅を維持し、垂直方向に拡大したいと思います。 TextViewのlayout_heightでwrap_contentを使用すると、2行目の後にテキストがクリップされます。 height属性またはlines属性を設定でき、親LinearLayoutが正しく展開されます。これをxml属性を使用して動的な高さにするにはどうすればよいですか?ここでwrap_contentのテキスト行をクリッピングするAndroid TextView
は、レイアウトコードです:ここで
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2017, University of Colorado Boulder
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="24dp">
<LinearLayout
android:id="@+id/image_and_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:onClick="launchSimulation"
android:paddingEnd="20dp"
android:scaleType="fitStart"
app:srcCompat="@drawable/logo" />
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Super long example text. Super long example text. Super long example text. Super long example text. Super long example text. Super long example text. Super long example text. Super long example text. Super long example text. " />
</LinearLayout>
は結果である:
:そして、ここでは、私はそれを見てみたい方法です
これは私にとっても役立ちました。ありがとう。 –
これは実行時にテキストが変更されても機能しません。 –