2017-09-11 7 views
0

水平方向のAndroid線形レイアウトでは、最初のテキストの長さが増加すると次のTextViewsが非表示になります。最初のテキストビューの長さが複数の行である場合、見えないテキストを囲むだけです。つまり、最初のテキストビューの長さが増えると、残りのビューが最初のビューの下に来るはずです。水平方向の線形レイアウトでは、長さが増加するとテキストが非表示になります

プログラムで向きを変更せずに達成できますか?次のように

私のコードは次のとおりです。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <com.mikhaellopez.circularimageview.CircularImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_margin="15dp" 
     android:scaleType="centerCrop" 
     app:civ_border_color="@color/colorAccent" 
     app:civ_border_width="5dp" 
     app:civ_border="true" 
     android:src="@drawable/user"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="80dp" 
     android:layout_marginStart="80dp" 
     android:layout_marginEnd="35dp" 
     android:layout_marginRight="35dp" 
     android:layout_marginTop="15dp" 
     android:orientation="vertical"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/app_name" 
      android:maxLines="2" 
      android:textColor="@android:color/black" 
      android:textSize="16sp" 
      android:ellipsize="end" 
      android:layout_margin="3dp"/> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_margin="3dp"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/app_name" 
       android:ellipsize="end" 
       android:maxLines="1" 
       android:textSize="14sp"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/period" 
       android:textSize="16sp" 
       android:layout_gravity="center_vertical" 
       android:layout_marginLeft="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginEnd="8dp" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/views" 
       android:textSize="14sp"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/period" 
       android:textSize="16sp" 
       android:layout_gravity="center_vertical" 
       android:layout_marginLeft="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginEnd="8dp" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hoursago" 
       android:textSize="14sp"/> 
     </LinearLayout> 
    </LinearLayout> 
    <ImageButton 
     android:id="@+id/popup" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end|center" 
     android:background="@null" 
     android:clickable="true" 
     android:padding="5dp" 
     android:layout_margin="5dp" 
     android:layout_centerInParent="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:src="@drawable/ic_overflow_grey_24dp" /> 
</RelativeLayout> 

私はそれぞれに次に、あなたのLinearLayoutに次の

android:weightSum="1" 

を追加

enter image description here

+0

下にしてみてくださいとしてのLinearLayoutの重みを割り当てることによって、これをアーカイブすることができますように。 –

+0

あなたはそれぞれのtexview –

+0

に重みを付けることによって試してみることができますが、テキストが指定された重み内で整列している重みを与えています。テキストを囲むだけです。つまり、最初のテキストビューの長さが長くなると、残りのビューが最初のビューになるはずです –

答えて

1

てみて画面を取得していますあなたのTextViewsのこれを行うことによって存在することができますどのくらいを追加します。

android:layout_weight="your value here" 

例ではこれは今のLinearLayoutの20%を充填させ

android:layout_weight="0.2" 

とすることができます。

0

は、[はい、あなたがHorizo​​ntalScrollViewを使用して、次のTextViewをacheiveすることができますかあなたが最初のTextViewの幅を修正することができ、コード

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="horizontal" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<com.mikhaellopez.circularimageview.CircularImageView 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_margin="15dp" 
    android:scaleType="centerCrop" 
    app:civ_border_color="@color/colorAccent" 
    app:civ_border_width="5dp" 
    app:civ_border="true" 
    android:src="@drawable/user"/> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_marginStart="80dp" 
    android:layout_marginEnd="35dp" 
    android:layout_marginRight="35dp" 
    android:layout_marginTop="15dp" 
    android:orientation="vertical"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:maxLines="2" 
     android:textColor="@android:color/black" 
     android:textSize="16sp" 
     android:ellipsize="end" 
     android:layout_margin="3dp"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_margin="3dp" 
     android:weightSum="8"> 
     <TextView 
      android:layout_weight="2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="StramTube" 
      android:ellipsize="end" 
      android:maxLines="1" 
      android:textSize="14sp" 
      /> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="*" 
      android:textSize="16sp" 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginRight="8dp" 
      android:layout_marginEnd="8dp" 
      android:layout_weight="1"/> 
     <TextView 
      android:layout_weight="2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="view" 
      android:textSize="14sp"/> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="*" 
      android:textSize="16sp" 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginRight="8dp" 
      android:layout_marginEnd="8dp" 
      android:layout_weight="1"/> 
     <TextView 
      android:layout_weight="2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Hours ago" 
      android:textSize="14sp"/> 
    </LinearLayout> 
</LinearLayout> 
<ImageButton 
    android:id="@+id/popup" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end|center" 
    android:background="@null" 
    android:clickable="true" 
    android:padding="5dp" 
    android:layout_margin="5dp" 
    android:layout_centerInParent="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:src="@drawable/ic_overflow_grey_24dp" /> 

関連する問題