0

良いリンクに案内するか、Androidでカスタムユーザーインターフェイスを構築できるようにするために勉強して読む必要のある基本的な要素を教えてください。私がカスタムで意味するのは、インターフェースには通常のAndroidボタンではなく画像であるボタンが含まれるということです。また、ユーザーの操作に基づいてその場でカスタムボタンを生成する必要があり、生成されたボタンにはイベントが関連付けられている必要があります。

4

1 に答える 1

1

ここにボタンに関する一般的な情報

ボタンに画像を使用するには、android.widget.ImageButtonが必要です。ドローアブルセレクターの例(res / drawable /に配置):

<selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/button_pressed" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/button_focused" /> <!-- focused -->
     <item android:drawable="@drawable/button_normal" /> <!-- default -->
 </selector>

そのため、さまざまな状態に応じてさまざまな画像を使用できます。その場でボタンを生成するには、任意のレイアウトマネージャー(FrameLayout、RelativeLayout、LinearLayout)を使用して基本レイアウトを定義し、アクティビティ内でID(findViewById())で検索し、表示します。

public void createContainerForImageView() { 
    LinearLayout container = new LinearLayout(this);  
    container.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
    container.setOrientation(LinearLayout.HORIZONTAL); 

    ImageView img=(ImageView)findViewById(R.id.ImageView01);
    Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
    int width=200;
    int height=200;
    Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);    
    img.setImageBitmap(resizedbitmap);

    container.addView(img); // or you can set the visibility of the img
}

お役に立てれば。

于 2011-11-17T15:53:03.467 に答える