页面布局(LinearLayout,RelativeLeyout)

任务1:使用线性布局实现如下界面的设计

代码:

修改activity_main.xml布局文件,将RelativetyLayoutgaiwei 改为LinearyLayout布局编码

<Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_weight="1"
        android:background="@android:color/black" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_weight="1"
        android:background="@android:color/darker_gray" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_weight="1"
        android:background="@color/blue" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_weight="1"
        android:background="@color/green" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_weight="1"
        android:background="@color/red" />

 

任务2使用相对布局实现如下界面的设计

代码:

activity_main.xml布局文件代码RelativeLayout编码

<TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Type here:" />

    <EditText
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/label"
        android:background="@android:drawable/editbox_background"
        />
   
    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="Ok"
    />
     <Button
        android:id="@+id/cancle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/ok"
        android:layout_toLeftOf="@id/ok"
        android:text="cancel"
    />

MainActivity.java编码

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.second, menu);
  return true;
 }
 //获取id,系统方法
 public boolean onOptionsItemSelected(MenuItem item){
  int id=item.getItemId();
  switch(id){
  case R.id.about:
   Toast.makeText(MainActivity.this, "作者:小不点\n时间:2013-3-26",Toast.LENGTH_LONG).show();   //显示提示讯息
  break;
     case R.id.exit:
  MainActivity.this.finish();
  break;
 }
  return true;
  
 }

}

 

 

 小结:学会使用三种布局文件,这样才能使你的页面更加漂亮

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值