coursera-android-week4-3 layout menus and action bar
来源:互联网 发布:mac系统打符号 编辑:程序博客网 时间:2024/06/06 21:43
public class LinearLayoutActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}
<?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="0dp" android:layout_weight="1" android:orientation="horizontal" > 代表水平排列 <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#aa0000" android:gravity="center_horizontal" android:text="red" android:textSize="24sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#00aa00" android:gravity="center_horizontal" android:text="green" android:textSize="24sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#0000aa" android:gravity="center_horizontal" android:text="blue" android:textSize="24sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#aaaa00" android:gravity="center_horizontal" android:text="yellow" android:textSize="24sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="row one" android:textSize="15pt" /> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="row two" android:textSize="15pt" /> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="row three" android:textSize="15pt" /> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="row four" android:textSize="15pt" /> </LinearLayout></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/entry" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Type here:" android:textSize="24sp" /> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" 关注这里 android:layout_below="@id/entry" android:layout_marginLeft="10dip" android:text="OK" android:textSize="24sp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/ok" 关注 android:layout_toLeftOf="@id/ok" 在ok的左边 android:text="Cancel" android:textSize="24sp" /></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="1" > <TableRow> <TextView android:layout_column="1" android:padding="3dip" android:text="Open..." android:textSize="24sp" /> <TextView android:gravity="right" android:padding="3dip" android:text="Ctrl-O" android:textSize="24sp" /> </TableRow> <TableRow> <TextView android:layout_column="1" android:padding="3dip" android:text="Save..." android:textSize="24sp" /> <TextView android:gravity="right" android:padding="3dip" android:text="Ctrl-S" android:textSize="24sp" /> </TableRow> <TableRow> <TextView android:layout_column="1" android:padding="3dip" android:text="Save As..." android:textSize="24sp" /> <TextView android:gravity="right" android:padding="3dip" android:text="Ctrl-Shift-S" android:textSize="24sp" /> </TableRow> <View android:layout_height="2dip" android:background="#FF909090" /> <TableRow> <TextView android:padding="3dip" android:text="X" android:textSize="24sp" /> <TextView android:padding="3dip" android:text="Import..." android:textSize="24sp" /> </TableRow> <TableRow> <TextView android:padding="3dip" android:text="X" android:textSize="24sp" /> <TextView android:padding="3dip" android:text="Export..." android:textSize="24sp" /> <TextView android:gravity="right" android:padding="3dip" android:text="Ctrl-E" android:textSize="24sp" /> </TableRow> <View android:layout_height="2dip" android:background="#FF909090" /> <TableRow> <TextView android:layout_column="1" android:padding="3dip" android:text="Quit" android:textSize="24sp" /> </TableRow></TableLayout>
<?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" > <GridView android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="match_parent" android:columnWidth="90dp" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:verticalSpacing="10dp" /></LinearLayout>
context 和 menus
public class HelloAndroidWithMenuActivity extends Activity {public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);TextView tv = (TextView) findViewById(R.id.text_view);registerForContextMenu(tv);//注册contextmenu}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {MenuInflater inflater = getMenuInflater();inflater 是解析 定义在xml 文件里边的layout用的 menuInflater 就是给menu用的inflater.inflate(R.menu.top_menu, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case R.id.help:Toast.makeText(getApplicationContext(), "you've been helped",//toast 是弹出的提示对话框Toast.LENGTH_SHORT).show();return true;case R.id.more_help:Toast.makeText(getApplicationContext(), "you've been helped more",Toast.LENGTH_SHORT).show();return true;case R.id.even_more_help:return true;default:return false;}}@Overridepublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {super.onCreateContextMenu(menu, v, menuInfo);MenuInflater inflater = getMenuInflater();inflater.inflate(R.menu.context_menu, menu);}@Overridepublic boolean onContextItemSelected(MenuItem item) {switch (item.getItemId()) {case R.id.help_guide:Toast.makeText(getApplicationContext(), "ContextMenu Shown",Toast.LENGTH_SHORT).show();return true;default:return false;}}}
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/help" android:icon="@drawable/ic_menu_help" android:title="@string/help"/> <item android:id="@+id/more_help" android:icon="@drawable/ic_menu_help" android:title="@string/more_help"/> <item android:id="@+id/even_more_help" android:icon="@drawable/ic_menu_help" android:title="@string/even_more_help"> <menu> <item android:id="@+id/give_up" android:title="@string/give_up"/> </menu> </item></menu>
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/help_guide" android:title="@string/guide"/></menu>
0 0
- coursera-android-week4-3 layout menus and action bar
- coursera-android-week4-4
- coursera-android-week4-1 views
- coursera-android-week4-2 viewgroup 和 adapter
- Android笔记 - UI Menu (3) Action Bar
- Android笔记 - UI Menu (3) Action Bar
- Action Bar for Android
- Action Bar for Android
- Android Fragment & Action Bar
- android action bar progress
- Android Action Bar
- Android UI--Action Bar
- Android Action Bar
- Action Bar of Android
- 【android studio】解决layout预览出现Rendering Problems Exception Unable to find the layout for Action Bar.
- 【android studio】解决layout预览出现Rendering Problems Exception Unable to find the layout for Action Bar.
- 【android studio】根本解决layout预览出现Rendering Problems Exception Unable to find the layout for Action Bar.
- android 去除title bar 标题栏 action bar
- 详解Mysql中InnoDB和MyISAM两种表类型的区别1
- MySQL中的Rows,Row_format以及MyISAM和InnoDB的一点区别
- MySQL-索引结构详解
- 用本地搭建Web服务器遇到的IP地址的问题
- new blog
- coursera-android-week4-3 layout menus and action bar
- [WebKit]管好页面缓存
- 【递推】【DP】-HDU-2175-汉诺塔⑨
- android xml异常:Attribute is missing the Android namespace prefix
- POJ 3617 Best Cow Line(字典序)
- android 关于底部控件遮挡上面list控件的解决办法
- hdu3183 RMQ模板 复杂度O(nlogn)
- 解读AtomicStampedReference的源码
- 内联函数与宏的比较