2014-03-26 5 views
1

단추 안에 작은 아이콘과 텍스트가있는 단추를 사용하려고합니다. 아이콘이 단추의 왼쪽에 있습니다. 어떻게 가운데에있는 텍스트에 더 가까이 이동할 수 있습니까?단추 안에 이미지와 텍스트가 나란히 표시됩니까?

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/home_icon" 
     android:text="BACK" 
     android:id="@+id/button" 
     android:width="160dp" 
     android:height="70dp" 
     android:textStyle="bold" /> 

답변

1

불행히도 drawableLeft 속성과 함께 할 수 없습니다. 이 속성은 이미지가 텍스트의 위치와 관계없이 맨 왼쪽 위치에 배치됩니다.

당신은이에 대한 자신의 버튼을 만들어야합니다

<LinearLayout 
    android:id="@+id/button" 
    style="?android:attr/buttonStyle" 
    android:layout_width="160dip" 
    android:layout_height="70dip" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/home_icon" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="BACK" 
     android:textColor="@android:color/black" /> 
</LinearLayout> 
0

당신은 가까이 이동 할 수 없습니다

이 버튼에 대한 내 XML이다. 귀하의 유일한 옵션은 당신이 그들을 가까이 함께 자신의 버튼을 구축해야 할 경우 :

<RelativeLayout 
      android:id="@+id/rlButton" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

    <TextView 
      android:id="@+id/tvText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_text"/> 

    <ImageView 
      android:id="@+id/ivLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/home_icon" 
      android:layout_toLeftOf="@id/tvText"/> 

</RelativeLayout> 

당신은 TextViewImageView 사이의 거리를 제어하기 위해 마진을 사용할 수 있습니다.

RelativeLayour rlButton = (RelativeLayout) view.findViewById(R.id.rlButton); 
rlButton.setOnClickListener(new OnClickListener() { 
    .... 
}); 

을하지만 물론 당신은 버튼과 동일한 모양 있도록 RelativeLayout의에 버튼 스타일을 적용해야한다 : 당신은 버튼으로 거의 동일하게 사용할 수 있습니다.

0
<Button 
android:id="@+id/button1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:drawableLeft="@android:drawable/btn_star_big_on" 
android:text="Drawable left"/> 
관련 문제