2012-05-11 3 views
0

Я использовал фоновое изображение для кнопки, но изображение растянуто и выглядит странно. Так может ли кто-нибудь помочь мне, что я могу сделать? Мой файл XML является:Как настроить изображение для кнопки?

<?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" android:layout_weight="2" android:background="@drawable/board" > 
    <ScrollView android:layout_weight="1" android:layout_marginLeft="30dp" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/scrollView1"> 
    <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_weight="1" > 

    <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent"> 
     <TextView android:text="1" android:textSize="30dp" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></TextView> 
     <ImageView android:id="@+id/imag1" android:src="@drawable/w10" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"> </ImageView> 
     <TextView android:id="@+id/no1" android:text="1" android:textSize="60dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></TextView> 

    </LinearLayout> 
    <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent"> 
     <TextView android:text="2" android:textSize="30dp" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></TextView> 
     <ImageView android:id="@+id/imag1" android:src="@drawable/w10" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"> </ImageView> 
     <TextView android:id="@+id/no2" android:text="2" android:textSize="60dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></TextView> 

    </LinearLayout> 
    <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent"> 
     <TextView android:text="3" android:textSize="30dp" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></TextView> 
     <ImageView android:id="@+id/imag1" android:src="@drawable/w10" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"> </ImageView> 
     <TextView android:id="@+id/no3" android:text="3" android:textSize="60dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></TextView> 
<Button android:id="@+id/practice" android:layout_width="wrap_content" android:layout_weight="1" android:background="@drawable/practice" android:layout_height="wrap_content" ></Button> 
      <Button android:id="@+id/home" android:layout_width="wrap_content" android:layout_weight="1" android:background="@drawable/home" android:layout_height="wrap_content" android:onClick="onClick"></Button> 

и мой файл Java является:

package com.android; 

import android.app.Activity; 
import android.content.Intent; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.ImageButton; 
import android.widget.TextView; 

public class Numbers extends Activity { 

    TextView[] txt = new TextView[20]; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.no); 
     Typeface tf = Typeface.createFromAsset(getBaseContext().getAssets(), "fonts/brhknd.ttf"); 

     for(int i = 0; i<mBtn.length; i++) 
     { 
     txt[i] = (TextView)findViewById(mBtn[i]); 
     txt[i].setTypeface(tf); 

     } 
     Button btnPractice = (Button)findViewById(R.id.practice); 
     btnPractice.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(Numbers.this,DrawingNumber.class); 
       startActivity(intent); 

      } 
     }); 

     Button btnHome = (Button)findViewById(R.id.home); 
     btnHome.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(Numbers.this,mainClass.class); 
       startActivity(intent); 

      } 
     }); 
    } 

    int[] mBtn = {R.id.no1,R.id.no2,R.id.no3,R.id.no4,R.id.no5,R.id.no6,R.id.no7,R.id.no8,R.id.no9,R.id.no10}; 


} 

Может кто-нибудь мне помочь? Заранее спасибо

+0

вы задали размеры кнопки, чтобы соответствовать изображение? – gunnx

+0

Нет, я не использовал – Delwin

ответ

2

Используйте ресурс с девятью патчами.

Nine-Patch

StateList

+0

Но у меня есть четыре кнопки в макете внизу. Они являются Previous, Practice, Home, а затем Next. – Delwin

+0

И? Сначала прочитайте документ. \ –

+0

Да. Я хочу сделать так, чтобы его можно было нажимать. – Delwin