zoukankan      html  css  js  c++  java
  • 控件布局_RelativeLayout

    android:layout_above 将该控件的底部至于给定ID的控件之上
    android:layout_below 将该控件的顶部至于给定ID的控件之下
    android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐
    android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐

    android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline(基准线)对齐
    android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘
    android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐
    android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐
    android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐


    android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐
    android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐
    android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐
    android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐

    android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央
    android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
    android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央

     1 import android.os.Bundle;
     2 import android.widget.Button;
     3 import android.app.Activity;
     4 
     5 public class Layout04 extends Activity {
     6     private Button ok;
     7     private Button cancel;
     8     @Override
     9     protected void onCreate(Bundle savedInstanceState) {
    10         super.onCreate(savedInstanceState);
    11         setContentView(R.layout.main);
    12         ok = (Button)findViewById(R.id.ok);
    13         cancel = (Button)findViewById(R.id.cancel);
    14         
    15         ok.setText(R.string.Ok);
    16         cancel.setText(R.string.Cancel);
    17     }
    18 }
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3                 android:layout_width="fill_parent"
     4                 android:layout_height="wrap_content"
     5                 android:padding="10px" >
     6 
     7     <TextView android:id="@+id/label" 
     8               android:layout_width="fill_parent" 
     9               android:layout_height="wrap_content" 
    10               android:text="Type here:" />
    11 
    12     <EditText 
    13               android:id="@+id/entry" 
    14               android:layout_width="fill_parent" 
    15               android:layout_height="wrap_content" 
    16               android:background="@android:drawable/editbox_background"
    17               android:layout_below="@id/label" />
    18   
    19     <Button android:id="@+id/ok" 
    20             android:layout_width="wrap_content" 
    21             android:layout_height="wrap_content" 
    22             android:layout_below="@id/entry"
    23             android:layout_alignParentRight="true"
    24             android:layout_marginLeft="10px"/>
    25             
    26     <Button android:id="@+id/cancel"
    27             android:layout_width="wrap_content" 
    28             android:layout_height="wrap_content"
    29             android:layout_toLeftOf="@id/ok"
    30             android:layout_alignTop="@id/ok"
    31             />
    32 </RelativeLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <string name="app_name">Layout04</string>
        <string name="action_settings">Settings</string>
        <string name="hello_world">Hello world!</string>
        <string name="Cancel">Cancel</string>
        <string name="Ok">okk</string>
    </resources>

    RelativeLayout布局4.2几新特性:
    android:layout_alignStart 表示将该控件放置在指定id控件的头部对齐
    android:layout_alignEnd 表示将该控件放置在指定id控件的尾部对齐
    android:layout_alignParentStart 如果为true,则将该控件放置在父控件的头部
    android:layout_alignParentEnd 如果为true,则将该控件放置在父控件的尾部

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:text="@string/hello_world" 
            />
        
         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@id/view"
            android:layout_below="@id/view"
            android:text="hfasdrld" 
            />
    
    </RelativeLayout>

    EditText控件的两个属性:

    android:hint="password" 设置EditText控件显示的文本
    android:inputType="" 设置EditText控件输入的类型

     1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:paddingBottom="@dimen/activity_vertical_margin"
     6     android:paddingLeft="@dimen/activity_horizontal_margin"
     7     android:paddingRight="@dimen/activity_horizontal_margin"
     8     android:paddingTop="@dimen/activity_vertical_margin"
     9     tools:context=".MainActivity" >
    10 
    11     <TextView
    12         android:id="@+id/myTextView"
    13         android:layout_width="match_parent"
    14         android:layout_height="wrap_content"
    15         android:gravity="center"
    16         android:text="@string/TextView1" />
    17     
    18     <EditText
    19         android:id="@+id/uersname"
    20         android:layout_width="wrap_content"
    21         android:layout_height="wrap_content"
    22         android:layout_alignParentLeft="true"
    23         android:layout_alignParentRight="true"
    24         android:layout_below="@id/myTextView"
    25         android:hint="uersname"
    26         />
    27     
    28     
    29      <EditText
    30         android:id="@+id/password"
    31         android:layout_width="wrap_content"
    32         android:layout_height="wrap_content"
    33         android:layout_alignLeft="@id/uersname"
    34         android:layout_alignRight="@id/uersname"
    35         android:layout_below="@id/uersname"
    36         android:hint="password"
    37         android:inputType="textPassword"
    38         />
    39      
    40      <Button
    41          android:id="@+id/myButton1"
    42          android:layout_width="wrap_content"
    43          android:layout_height="wrap_content"
    44          android:layout_alignParentRight="true"
    45          android:layout_below="@id/password"
    46          android:text="@string/Button1"
    47          />
    48 
    49       <Button
    50           android:id="@+id/myButton2"
    51           android:layout_width="wrap_content"
    52           android:layout_height="wrap_content"
    53           android:layout_alignBaseline="@+id/myButton1"
    54           android:layout_alignBottom="@+id/myButton1"
    55           android:layout_toLeftOf="@+id/myButton1"
    56           android:text="@string/Button2" />
    57 
    58 </RelativeLayout>
  • 相关阅读:
    对象和接口简单比较
    DevExpress报表开发基本流程
    有关ExecuteNonQuery返回值的分析
    2012年度计划
    小测试:有关++i&&i++,你是不是看晕了
    “PE文件格式”1.9版 完整译文
    .NET中的入口及幕后英雄:MSCorEE.dll(转)
    软件构建过程中的隐喻
    转:地图导出格式,教你如何选择
    推荐几个网站
  • 原文地址:https://www.cnblogs.com/LO-ME/p/3585167.html
Copyright © 2011-2022 走看看