2016-05-29 6 views
1

私はTextViewとImageViewをCardViewに持っています。
TextViewに1つ問題があります。
TextViewのテキストがCardViewの長さよりも長い場合、ImageViewに対して表示されますが、これは必要ありません。同じ行のtextViewの横にImageViewを追加する

この写真:

enter image description here

テキストがImageIiewに触れると、それはテキストの継続を示すため...を示しているので、私はそれをしたいです。

row.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:layout_margin="4dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/txt_file_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true"/> 

     <ImageView 
      android:layout_width="24dp" 
      android:layout_height="24dp" 
      android:src="@drawable/ic_delete_forever_red_500_24dp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true"/> 

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

これは私が何をしたいのスクリーンショットです:

enter image description here

+1

drawableleftを追加します(描画イメージを入れて)、あなたが何をしたいあなたのTextView –

+0

ショーのスクリーンショットでパディングdrawablepaddingを入れてみてください。 – Ironman

+0

@アイロンマン私の目標からスクリーンショットを追加します。 –

答えて

2

代わりのRelativeLayoutでImageViewのとのTextViewを入れて、あなた化合物引出し可能を利用することができます。
ドロウアブルを追加することができるという意味は、の内側にあるの内側ではなく、TextViewです。

すなわち:あなたは一度のViewGroupとビューを取り払うため

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:layout_margin="4dp"> 
     <TextView 
      android:id="@+id/txt_file_title" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerInParent="true" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:drawableLeft="@drawable/ic_delete_forever_red_500_24dp" 
     /> 
</android.support.v7.widget.CardView> 

これは、速くもある(より少ないあなたがより速く、使用)

必要に応じて、あなたもを設定することができますandroid:drawablePadding属性を使用して、複合ドロアブルとテキストの間のマージンを設定します。

2

希望しますか?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:layout_margin="4dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/txt_file_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/imageView" 
      android:layout_marginLeft="16dp" 
      android:layout_centerVertical="true"/> 

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="24dp" 
      android:layout_height="24dp" 
      android:src="@drawable/ic_delete_forever_red_500_24dp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true"/> 


    </RelativeLayout> 
</android.support.v7.widget.CardView> 
+0

not working !!!! –

+0

これはテスト済みです。どのように動作しません:O。私の終わりの出力http://imgur.com/BcvwVFr – Masum

+0

私の平均は私に適していません! –

1

このコードを使用してください。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:layout_margin="4dp" 
    android:orientation="horizontal"> 


    <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="24dp" 
       android:layout_height="24dp" 
       android:src ="@drawable/ic_delete_forever_red_500_24dp" 
       android:id="@+id/imageView" 
       android:layout_centerVertical="true"/> 

      <TextView 
       android:id="@+id/txt_file_title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="bjbjgbdgkgbndbndkbdkb..fg.bgbfgnbnfgb." 
       android:layout_toEndOf="@+id/imageView" 
       android:layout_toRightOf="@+id/imageView" 
       android:layout_centerVertical="true"/> 

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

あなたの出力はこのようになります。

enter image description here

関連する問題