상단에 이미지가 있고 하단에 텍스트가있는 버튼이 필요합니다. 이미지와 텍스트 모두 런타임 중에 결정되므로 각 버튼에 대해 ImageButton의 setImageBitmap과 Button의 setText를 결합 할 수 있기를 원합니다.이미지와 텍스트가 포함 된 Android ImageButton
아이디어가 있으십니까?
감사 크리스
상단에 이미지가 있고 하단에 텍스트가있는 버튼이 필요합니다. 이미지와 텍스트 모두 런타임 중에 결정되므로 각 버튼에 대해 ImageButton의 setImageBitmap과 Button의 setText를 결합 할 수 있기를 원합니다.이미지와 텍스트가 포함 된 Android ImageButton
아이디어가 있으십니까?
감사 크리스
나는 마침내 내가 찾던 것을 발견했다.
ImageButton이 아닌 텍스트와 이미지가있는 Button 용이므로 원래의 솔루션은 아닙니다. 문제지만 해결 방법. –
내가 그렇게 할 수있는 쉬운 방법이라고 생각하지 않습니다.
나는 custom-component을 만들 것입니다.
setCompoundDrawablesWithIntrinsicBounds 나 날의 setText를 사용시키는 동시에, 버튼에 비트 맵/드로어 블을 할당 할 수 있습니다 :
예를 들어
button.setCompoundDrawablesWithIntrinsicBounds처럼 뭔가를 할 버튼의 상단에 비트 맵 이미지를 설정하려면 (null의 경우, 새로운 BitmapDrawable (bitmapimage), NULL, NULL);
두 이미지를 모두 둘러보기 버튼과 텍스트 이미지 버튼의 배경에있는 텍스트를 재정의하려면 .... 코드를 봅니다. 예 :
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="69dp"
android:layout_marginTop="96dp"
android:background="@drawable/icon"
android:scaleType="fitXY" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Droid"
android:textColor="#ff0000"
android:textSize="24dip" >
</TextView>
</FrameLayout>
중복 : http://stackoverflow.com/questions/1532876/android-combining-text-image-on-a-button-or-imagebutton – ognian
나는 요청하기 전에 그 질문에 보였다,하지만 난 그 이유는 다음과 같습니다. 1. 이미지를 배경으로 설정할 수 없으며 이미지를 맨 위에, 텍스트를 이미지 위에 표시하고 텍스트를 이미지 위에 표시하지 않을 수 있습니다. 2. 프로그래밍 방식으로 설정해야하며 xml을 사용할 수 없습니다 – Chris
다른 답변에서 내 대답을 확인하십시오. http://stackoverflow.com/questions/3148713/inflating-a-view-into-button/3149052#3149052 – ognian