2017-07-02 78 views
0

我需要在我的textview中添加一個drawable,並使其具有與文本相同的高度。如何繪製高度取決於textview的文本高度?

我的XML:

...<LinearLayout 
     android:id="@+id/line6" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tableLayoutId"> 

     <TextView 
      android:id="@+id/label10" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingEnd="2dp" 
      android:paddingRight="2dp" 
      android:drawableRight="@drawable/greenarrowup" 
      android:drawableEnd="@drawable/greenarrowup" 
      /> ... 

什麼我越來越: Actual result

我想要什麼: desired result

我一直在使用的ImageView,以獲得期望的結果嘗試,但沒」不要這樣做,有人可以幫我嗎?
謝謝。

+0

有趣的問題。請參閱[這個問題和答案](https://stackoverflow.com/questions/9168021/compounddrawable-size)。 – Cheticamp

回答

0

應設置線性佈局的水平方向和使用這樣的ImageView的:

<LinearLayout 
     android:id="@+id/line6" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@+id/tableLayoutId"> 

     <TextView 
      android:id="@+id/label10" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingEnd="2dp" 
      android:paddingRight="2dp" 
      /> 

     <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/greenarrowup" /> 


     </LinearLayout> 
+0

謝謝你的回答,但它沒有奏效。 – hereForLearing

0

添加一定高度上的TextView並設置重力垂直居中

+0

謝謝你的回答,但這不是我所需要的。 – hereForLearing