2011-11-17 52 views
0

我希望您能够指导我良好的链接或给我必须学习和阅读的基本元素,以便能够在android中构建自定义用户界面。 我的意思是,界面将包含不是普通的android按钮的图像按钮。 另外,我必须根据用户操作即时生成自定义按钮,并且这些生成的按钮应具有与它们关联的事件。在Android中使用图形构建自定义界面

+0

按钮,臀部或小腿? – Ricky

+0

取决于如果你的母语是英语或jewesh ياوجهالبطمة – bogha

回答

1

大约按钮here

通用信息要使用图像您需要android.widget.ImageButton的按钮。绘制选择的示例(把它放在RES /绘制/):

<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 
} 

希望这帮助。

相关问题