2016-10-25 10 views
0

なぜ私のリニアレイアウトはCardView内の全領域を占めていないのですか? プレビューを使用してLinearLayoutを展開してCardViewsの幅に合わせると、幅をmatch_parent(手作業で試しました)に設定しますが、現在の状態に戻ります。 言い換えれば、私は赤い背景を右に、そして右のTextViewを右に揃えたいと思います。CardView内のLinearLayoutが全体の空白を埋めていない

enter image description here

<LinearLayout 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.support.v7.widget.CardView 
    android:id="@+id/itemCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="3dp" 
    android:layout_marginBottom="3dp" 
    android:layout_marginTop="3dp" 
    android:background="@color/Mat" 
    android:padding="3dp" 
    app:cardElevation="4dp" 
    app:cardCornerRadius="1dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:animateLayoutChanges="true" 
     android:background="@color/Mat" 
     android:orientation="horizontal" 
     android:padding="3dp" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp"> 


     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="80dp" 
      android:layout_height="80dp" 
      android:background="@drawable/circle" 
      android:gravity="center" 
      android:text="DEU" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="Frau Hardt" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:id="@+id/textView4" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="O03" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

    </LinearLayout> 

</android.support.v7.widget.CardView> 

</LinearLayout> 

編集:最小幅を削除し、match_parentする全体レイアウトの幅を設定した後、それはすべての道を右に行きます。 ここでは、TextViewの名前を横に並べて、レイアウト全体の右にテキストビューを右に並べる方法を教えてください。

私はお互いのすぐ隣に素敵に見えるので、画像が含まれていました。私はコードが(特にそれがたくさんあるわけではないので)テキストとしてである必要はないことを願っています。もしそうなら、私はもちろん質問を編集します! ありがとう!

+1

コードをXMLとして投稿できますか? –

+4

カードビューから最小幅と最小高さを削除してください –

答えて

1

これで中間のTextViewを作成します。

<TextView 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    ... /> 

残りの中間スペースを埋める。

fill_parentの代わりにmatch_parentを使用することも推奨されています。

+0

これまでこの方法について聞いたことがありません!ありがとう – Crosswind

関連する問題