2014-04-27 2 views
1

이미지를 이미지 버튼 크기로 조정하는 데 문제가 있습니다. 사실 내 단추는 너무 큰 이미지를 보유하고 있으며 이미지 단추에서 내 그림의 일부만 볼 수 있습니다.Android에서 이미지 버튼의 동적 크기 이미지

1/8의 크기로 하단에있는 버튼이있는 웹보기를 정의하는 레이아웃이있는 액티비티가 있습니다. 웹뷰에는 화면의 8 개 부분과 버튼 1 부분이 필요합니다. 내 레이아웃은 다음과 같이 간단하게 보인다 : 무게 때문에 정의의

WebView 
    ... 
    ... 
    android:layout_weight="8"/
LinearLayout 
    ... 
    ... 
    android:layout_weight="1" 
    <ImageButton 
    ... 
    android:layout_weight="1"/ 
/LinearLayout 

, 내 버튼의 pixelsize을 모르는 내가 제대로하지 크기의 버튼에 내 사진을 수 있습니다.

이미지를 버튼에 올바르게 표시하려면 어떻게해야합니까? 아니면 내 버튼이 제 버튼에 정확하게 맞춰 졌는지 어떻게 관리 할 수 ​​있습니까?

+2

여기에 관련 답변이 있습니다. http://stackoverflow.com/questions/15116393/fit-image-in-imagebutton-in-android –

+0

그게 전부입니다. 고마워요! –

답변

0

내 코드 아래에서 도움을 받으시기 바랍니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:background="#000" 
      android:layout_weight="7" /> 

     <Button 
      android:id="@+id/bLogin" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:background="#ff0000" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</LinearLayout> 

이제 원하는대로 수정할 수 있습니다. 행운을 빌어 요!