Activity去除标题:在setContentView之前添加requestWindowFeature(Window.FEATURE_NO_TITLE);
RelativeLayout下Button居中:
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
LinearLayout下两个Button平分一行:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定"
android:layout_weight="1"
android:id="@+id/ok"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="取消"
android:layout_weight="1"
android:id="@+id/cancle"/>
九宫格布局:
XML:
<span style="white-space:pre"></span><pre name="code" class="html"><GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"/>
</pre><p></p><pre>
JAVA:
GridView gridview = (GridView) findViewById(R.id.gridview);
//生成动态数组,并且转入数据
ArrayList<HashMap<String, Object>> lstItem = new ArrayList<HashMap<String, Object>>();
for(int i=0;i<itemText.length;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.ic_launcher);//添加图像资源的ID
map.put("ItemText", itemText[i]);//按序号做ItemText
lstItem.add(map);
}
//生成适配器的ImageItem <====> 动态数组的元素,两者一一对应
SimpleAdapter saImageItems = new SimpleAdapter(this,lstItem,R.layout.gridmenu_item,new String[] {"ItemImage","ItemText"},new int[] {R.id.ItemImage,R.id.ItemText});
//添加并且显示
gridview.setAdapter(saImageItems);
//添加消息处理
gridview.setOnItemClickListener(new GridView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
switch (arg2)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
});
滚动条:
只需在要显示滚动条的View外面加上:<pre name="code" class="html"><ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
...
</ScrollView>
ImageView点击效果:
mButton.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_DOWN){
((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.button_pressed));
}
else
if(event.getAction() == MotionEvent.ACTION_UP){
((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.button));
}
return false;
}
});
</pre><pre name="code" class="java">建议:个人以前写布局时总是直接写XML代码,很少用Graphical Layout,但最近用了Graphical Layout后觉得还挺不错的,就是经常会有些东西得自己再做代码上的调整,修改,但总体来说,帮助还挺大的。所以,推荐大家使用哈。
PS:仅做为一个技术渣的观点。