xamarin android布局

来源:互联网 发布:网络机柜批发cqwsjg 编辑:程序博客网 时间:2024/06/05 02:48

xamarin android布局练习(1)

xamarin Android布局练习,基础非常重要,首先要学习的就是android的布局练习,xamarin也一样,做了几个xamarin android的布局例子,多练习几遍就能学会这个布局,当然有写css的学习这个android的布局很容易入门。

当你看到这篇文章的时候,你应该知道字体图标,下面很多图标都是直接从上面下载的,非常的牛逼,这个字体图标有必要科普一下,这个链接

字体图标下载

首先来看看要做成什么样子的

主要的关键点就是:gravity对其方式,relative布局, linear布局,width,height,orientation方向

代码:

[html] view plain copy
print?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#dedede"  
  6.     android:id="@+id/relativeLayout">  
  7.     <LinearLayout  
  8.         android:id="@+id/linear1"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:background="#c6c6c6"  
  12.         android:gravity="center">  
  13.         <TextView  
  14.             android:layout_width="match_parent"  
  15.             android:layout_height="wrap_content"  
  16.             android:text="请登录"  
  17.             android:textSize="20sp"  
  18.             android:gravity="center"  
  19.             android:layout_marginTop="20dp"  
  20.             android:layout_marginBottom="20dp"  
  21.             android:textColor="#808080" />  
  22.     </LinearLayout>  
  23.     <LinearLayout  
  24.         android:layout_width="match_parent"  
  25.         android:layout_height="wrap_content"  
  26.         android:layout_below="@+id/linear1"  
  27.         android:orientation="vertical"  
  28.         android:id="@+id/linear2">  
  29.     <!--相对布局-->  
  30.         <LinearLayout  
  31.             android:layout_width="match_parent"  
  32.             android:layout_height="wrap_content"  
  33.             android:orientation="horizontal"  
  34.             android:clickable="true"  
  35.             android:id="@+id/linear3">  
  36.             <ImageView  
  37.                 android:layout_width="wrap_content"  
  38.                 android:layout_height="wrap_content"  
  39.                 android:src="@drawable/xiaoxi"  
  40.                 android:layout_gravity="center"  
  41.                 android:layout_marginLeft="10dp" />  
  42.             <TextView  
  43.                 android:layout_width="match_parent"  
  44.                 android:layout_height="wrap_content"  
  45.                 android:text="@string/xiaoxi"  
  46.                 android:textColor="@color/test_bg"  
  47.                 android:gravity="center"  
  48.                 android:textSize="30sp"  
  49.                 android:layout_marginTop="10dp"  
  50.                 android:layout_marginBottom="10dp" />  
  51.         </LinearLayout>  
  52.         <View  
  53.             android:layout_width="match_parent"  
  54.             android:layout_height="1dp"  
  55.             android:background="#999999" />  
  56.     </LinearLayout>  
  57.     <LinearLayout  
  58.         android:layout_width="fill_parent"  
  59.         android:layout_height="wrap_content"  
  60.         android:layout_below="@+id/linear2"  
  61.         android:id="@+id/linear4"  
  62.         android:orientation="vertical"  
  63.         android:clickable="true">  
  64.         <LinearLayout  
  65.             android:layout_width="match_parent"  
  66.             android:layout_height="wrap_content"  
  67.             android:orientation="horizontal">  
  68.             <ImageView  
  69.                 android:layout_width="wrap_content"  
  70.                 android:layout_height="wrap_content"  
  71.                 android:src="@drawable/school"  
  72.                 android:layout_gravity="center"  
  73.                 android:layout_marginLeft="10dp" />  
  74.             <TextView  
  75.                 android:layout_width="match_parent"  
  76.                 android:layout_height="wrap_content"  
  77.                 android:text="校园活动"  
  78.                 android:textSize="30sp"  
  79.                 android:textColor="#808080"  
  80.                 android:gravity="center"  
  81.                 android:layout_marginTop="10dp"  
  82.                 android:layout_marginBottom="10dp" />  
  83.         </LinearLayout>  
  84.         <View  
  85.             android:layout_height="1dp"  
  86.             android:layout_width="match_parent"  
  87.             android:background="#999999" />  
  88.     </LinearLayout>  
  89.     <LinearLayout  
  90.         android:orientation="vertical"  
  91.         android:layout_width="match_parent"  
  92.         android:layout_height="wrap_content"  
  93.         android:layout_below="@+id/linear4"  
  94.         android:clickable="true">  
  95.         <LinearLayout  
  96.             android:orientation="horizontal"  
  97.             android:layout_width="match_parent"  
  98.             android:layout_height="wrap_content">  
  99.             <ImageView  
  100.                 android:id="@+id/img1"  
  101.                 android:src="@drawable/taobao"  
  102.                 android:layout_gravity="center"  
  103.                 android:layout_height="wrap_content"  
  104.                 android:layout_width="wrap_content"  
  105.                 android:layout_marginLeft="10dp" />  
  106.             <TextView  
  107.                 android:text="@string/taobao"  
  108.                 android:textColor="@color/test_bg"  
  109.                 android:textSize="30sp"  
  110.                 android:layout_height="wrap_content"  
  111.                 android:layout_width="match_parent"  
  112.                 android:layout_marginTop="10dp"  
  113.                 android:layout_marginBottom="10dp"  
  114.                 android:gravity="center" />  
  115.         </LinearLayout>  
  116.     </LinearLayout>  
  117. </RelativeLayout>  

xamarin android布局练习(2)

看看效果图2

代码如下:

[html] view plain copy
print?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_height="match_parent"  
  4.     android:layout_width="match_parent"  
  5.     android:id="@+id/linear1"  
  6.     android:orientation="vertical">  
  7.     <LinearLayout  
  8.         android:layout_height="wrap_content"  
  9.         android:layout_width="match_parent"  
  10.         android:id="@+id/linear2"  
  11.         android:orientation="vertical"  
  12.         android:background="#dedede">  
  13.         <TextView  
  14.             android:layout_height="wrap_content"  
  15.             android:layout_width="match_parent"  
  16.             android:textColor="#808080"  
  17.             android:textSize="20dp"  
  18.             android:text="如何使用xamarin布局练习"  
  19.             android:layout_marginTop="10dp"  
  20.             android:layout_marginBottom="10dp" />  
  21.         <RelativeLayout  
  22.             android:layout_height="wrap_content"  
  23.             android:layout_width="match_parent"  
  24.             android:id="@+id/relative1">  
  25.             <ImageView  
  26.                 android:id="@+id/imgCenter"  
  27.                 android:layout_height="100dp"  
  28.                 android:layout_width="100dp"  
  29.                 android:layout_centerInParent="true"  
  30.                 android:src="@drawable/taobao" />  
  31.             <ImageView  
  32.                 android:id="@+id/imgLeft"  
  33.                 android:layout_alignParentLeft="true"  
  34.                 android:layout_height="100dp"  
  35.                 android:layout_width="100dp"  
  36.                 android:src="@drawable/taobao1" />  
  37.             <ImageView  
  38.                 android:id="@+id/imgRight"  
  39.                 android:layout_alignParentRight="true"  
  40.                 android:layout_height="100dp"  
  41.                 android:layout_width="100dp"  
  42.                 android:src="@drawable/taobao1" />  
  43.         </RelativeLayout>  
  44.         <LinearLayout  
  45.             android:layout_height="wrap_content"  
  46.             android:layout_marginTop="10dp"  
  47.             android:layout_width="match_parent"  
  48.             android:orientation="horizontal"  
  49.             android:id="@+id/relative2">  
  50.             <TextView  
  51.                 android:textColor="#999999"  
  52.                 android:textSize="15dp"  
  53.                 android:text="手机腾讯网"  
  54.                 android:id="@+id/txt1"  
  55.                 android:layout_height="wrap_content"  
  56.                 android:layout_width="wrap_content" />  
  57.             <TextView  
  58.                 android:textColor="#999999"  
  59.                 android:textSize="15dp"  
  60.                 android:text="评论  89"  
  61.                 android:layout_height="wrap_content"  
  62.                 android:layout_width="wrap_content"  
  63.                 android:layout_gravity="right" />  
  64.         </LinearLayout>  
  65.         <View  
  66.             android:layout_height="1dp"  
  67.             android:layout_width="match_parent"  
  68.             android:background="#808080" />  
  69.     </LinearLayout>  
  70.     <LinearLayout  
  71.         android:layout_height="wrap_content"  
  72.         android:layout_width="match_parent"  
  73.         android:id="@+id/linear21"  
  74.         android:orientation="vertical"  
  75.         android:background="#dedede"  
  76.         android:layout_marginTop="10dp">  
  77.         <TextView  
  78.             android:layout_height="wrap_content"  
  79.             android:layout_width="match_parent"  
  80.             android:textColor="#808080"  
  81.             android:textSize="20dp"  
  82.             android:text="如何使用xamarin布局练习2"  
  83.             android:layout_marginTop="10dp"  
  84.             android:layout_marginBottom="10dp" />  
  85.         <RelativeLayout  
  86.             android:layout_height="wrap_content"  
  87.             android:layout_width="match_parent"  
  88.             android:id="@+id/relative11">  
  89.             <ImageView  
  90.                 android:id="@+id/imgCenter1"  
  91.                 android:layout_height="100dp"  
  92.                 android:layout_width="100dp"  
  93.                 android:layout_centerInParent="true"  
  94.                 android:src="@drawable/taobao" />  
  95.             <ImageView  
  96.                 android:id="@+id/imgLeft1"  
  97.                 android:layout_alignParentLeft="true"  
  98.                 android:layout_height="100dp"  
  99.                 android:layout_width="100dp"  
  100.                 android:src="@drawable/taobao1" />  
  101.             <ImageView  
  102.                 android:id="@+id/imgRight1"  
  103.                 android:layout_alignParentRight="true"  
  104.                 android:layout_height="100dp"  
  105.                 android:layout_width="100dp"  
  106.                 android:src="@drawable/taobao1" />  
  107.         </RelativeLayout>  
  108.         <LinearLayout  
  109.             android:layout_height="wrap_content"  
  110.             android:layout_marginTop="10dp"  
  111.             android:layout_width="match_parent"  
  112.             android:orientation="horizontal"  
  113.             android:id="@+id/relative21">  
  114.             <TextView  
  115.                 android:textColor="#999999"  
  116.                 android:textSize="15dp"  
  117.                 android:text="手机腾讯网"  
  118.                 android:id="@+id/txt11"  
  119.                 android:layout_height="wrap_content"  
  120.                 android:layout_width="wrap_content" />  
  121.             <TextView  
  122.                 android:textColor="#999999"  
  123.                 android:textSize="15dp"  
  124.                 android:text="评论  89"  
  125.                 android:layout_height="wrap_content"  
  126.                 android:layout_width="wrap_content"  
  127.                 android:layout_gravity="right" />  
  128.         </LinearLayout>  
  129.     </LinearLayout>  
  130. </LinearLayout>  
主要的关键点在于:relative布局,
[html] view plain copy
print?
  1. android:layout_alignParentLeft="true"  
这个属性非常重要,在父容器中的对其方式,bool类型的。layout_alignParentLeft="true"在父容器中左对齐

xamarin android布局练习(3)

效果图:


代码如下:

[html] view plain copy
print?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_height="match_parent"  
  4.     android:layout_width="match_parent"  
  5.     android:id="@+id/relative"  
  6.     android:background="#dedede">  
  7.     <ImageView  
  8.         android:layout_height="64dp"  
  9.         android:layout_width="64dp"  
  10.         android:id="@+id/imgCenter"  
  11.         android:src="@drawable/taobao"  
  12.         android:layout_centerInParent="true" />  
  13.     <ImageView  
  14.         android:layout_height="64dp"  
  15.         android:layout_width="64dp"  
  16.         android:id="@+id/imgTop"  
  17.         android:src="@drawable/wangwang"  
  18.         android:layout_above="@+id/imgCenter"  
  19.         android:layout_centerHorizontal="true" />  
  20.     <ImageView  
  21.         android:layout_height="64dp"  
  22.         android:layout_width="64dp"  
  23.         android:id="@+id/imgRight"  
  24.         android:src="@drawable/suning"  
  25.         android:layout_toRightOf="@+id/imgCenter"  
  26.         android:layout_centerVertical="true" />  
  27.     <ImageView  
  28.         android:layout_height="64dp"  
  29.         android:layout_width="64dp"  
  30.         android:id="@+id/imgLeft"  
  31.         android:src="@drawable/suning"  
  32.         android:layout_toLeftOf="@+id/imgCenter"  
  33.         android:layout_centerVertical="true" />  
  34.     <ImageView  
  35.         android:layout_height="64dp"  
  36.         android:layout_width="64dp"  
  37.         android:id="@+id/imgBottom"  
  38.         android:src="@drawable/jingsong"  
  39.         android:layout_below="@+id/imgCenter"  
  40.         android:layout_centerHorizontal="true" />  
  41. </RelativeLayout>  

关键点在于如何使用relative的各种对其方式



xamarin android布局练习简单的登录(4)

效果如下:
只用了一个linear布局
[html] view plain copy
print?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:background="@color/loginBgColor">  
  7.     <LinearLayout  
  8.         android:layout_height="wrap_content"  
  9.         android:layout_width="match_parent"  
  10.         android:id="@+id/linear1"  
  11.         android:orientation="vertical">  
  12.         <TextView  
  13.             android:id="@+id/txt"  
  14.             android:layout_height="wrap_content"  
  15.             android:layout_width="wrap_content"  
  16.             android:layout_marginTop="30dp"  
  17.             android:layout_marginBottom="30dp"  
  18.             android:layout_marginRight="30dp"  
  19.             android:layout_gravity="right"  
  20.             android:text="设备登录"  
  21.             android:textColor="@color/whiteColor"  
  22.             android:textSize="20dp" />  
  23.     </LinearLayout>  
  24.     <LinearLayout  
  25.         android:id="@+id/linear2"  
  26.         android:layout_height="wrap_content"  
  27.         android:layout_width="match_parent"  
  28.         android:orientation="vertical">  
  29.         <TextView  
  30.             android:id="@+id/txt2"  
  31.             android:layout_height="wrap_content"  
  32.             android:layout_width="wrap_content"  
  33.             android:textSize="30dp"  
  34.             android:textColor="@color/whiteColor"  
  35.             android:layout_gravity="center"  
  36.             android:text="LOGO"  
  37.             android:layout_marginTop="20dp"  
  38.             android:layout_marginBottom="20dp" />  
  39.     </LinearLayout>  
  40.     <LinearLayout  
  41.         android:id="@+id/linear3"  
  42.         android:layout_height="wrap_content"  
  43.         android:layout_width="match_parent"  
  44.         android:orientation="vertical"  
  45.         android:layout_marginLeft="20dp"  
  46.         android:layout_marginRight="20dp">  
  47.         <EditText  
  48.             android:id="@+id/txtUserName"  
  49.             android:background="@color/whiteColor"  
  50.             android:hint="请输入用户名"  
  51.             android:focusable="true"  
  52.             android:layout_width="match_parent"  
  53.             android:layout_height="50dp"  
  54.             android:textSize="20dp"  
  55.             android:textColor="#000000"  
  56.             android:paddingLeft="10dp"  
  57.             android:textCursorDrawable="@null" />  
  58.         <View  
  59.             android:layout_width="match_parent"  
  60.             android:layout_height="1dp"  
  61.             android:background="#dedede" />  
  62.         <EditText  
  63.             android:id="@+id/txtPassword"  
  64.           android:background="@color/whiteColor"  
  65.             android:hint="请输入密码1"  
  66.             android:textCursorDrawable="@null"  
  67.             android:inputType="textPassword"  
  68.             android:layout_width="match_parent"  
  69.             android:layout_height="50dp"  
  70.             android:textSize="20dp"  
  71.             android:paddingLeft="10dp"  
  72.             android:textColor="#000000" />  
  73.         <Button  
  74.             android:id="@+id/btnLogin"  
  75.             android:text="登录"  
  76.             android:layout_height="50dp"  
  77.             android:layout_width="match_parent"  
  78.             android:textColor="@color/whiteColor"  
  79.             android:background="#2894FF"  
  80.             android:textSize="20dp"  
  81.             android:paddingTop="5dp"  
  82.             android:paddingBottom="5dp"  
  83.             android:layout_marginTop="20dp" />  
  84.     </LinearLayout>  
  85.     <LinearLayout  
  86.         android:layout_height="wrap_content"  
  87.         android:layout_width="match_parent"  
  88.         android:orientation="horizontal"  
  89.         android:layout_marginLeft="20dp"  
  90.         android:layout_marginTop="10dp"  
  91.         android:id="@+id/linear5">  
  92.         <CheckBox  
  93.             android:id="@+id/checkbox_remeberUser"  
  94.             android:layout_height="30dp"  
  95.             android:layout_width="30dp"  
  96.             android:textColor="#336699"  
  97.             android:textColorHighlight="#336699" />  
  98.         <TextView  
  99.             android:id="@+id/remeberUser"  
  100.             android:layout_height="wrap_content"  
  101.             android:layout_width="wrap_content"  
  102.             android:text="记住该用户"  
  103.             android:textColor="#FFFFFF"  
  104.             android:textSize="16dp" />  
  105.     </LinearLayout>  
  106. </LinearLayout>  

    xamarin android布局练习(1)

    xamarin Android布局练习,基础非常重要,首先要学习的就是android的布局练习,xamarin也一样,做了几个xamarin android的布局例子,多练习几遍就能学会这个布局,当然有写css的学习这个android的布局很容易入门。

    当你看到这篇文章的时候,你应该知道字体图标,下面很多图标都是直接从上面下载的,非常的牛逼,这个字体图标有必要科普一下,这个链接

    字体图标下载

    首先来看看要做成什么样子的

    主要的关键点就是:gravity对其方式,relative布局, linear布局,width,height,orientation方向

    代码:

    [html] view plain copy
    print?
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:background="#dedede"  
    6.     android:id="@+id/relativeLayout">  
    7.     <LinearLayout  
    8.         android:id="@+id/linear1"  
    9.         android:layout_width="match_parent"  
    10.         android:layout_height="wrap_content"  
    11.         android:background="#c6c6c6"  
    12.         android:gravity="center">  
    13.         <TextView  
    14.             android:layout_width="match_parent"  
    15.             android:layout_height="wrap_content"  
    16.             android:text="请登录"  
    17.             android:textSize="20sp"  
    18.             android:gravity="center"  
    19.             android:layout_marginTop="20dp"  
    20.             android:layout_marginBottom="20dp"  
    21.             android:textColor="#808080" />  
    22.     </LinearLayout>  
    23.     <LinearLayout  
    24.         android:layout_width="match_parent"  
    25.         android:layout_height="wrap_content"  
    26.         android:layout_below="@+id/linear1"  
    27.         android:orientation="vertical"  
    28.         android:id="@+id/linear2">  
    29.     <!--相对布局-->  
    30.         <LinearLayout  
    31.             android:layout_width="match_parent"  
    32.             android:layout_height="wrap_content"  
    33.             android:orientation="horizontal"  
    34.             android:clickable="true"  
    35.             android:id="@+id/linear3">  
    36.             <ImageView  
    37.                 android:layout_width="wrap_content"  
    38.                 android:layout_height="wrap_content"  
    39.                 android:src="@drawable/xiaoxi"  
    40.                 android:layout_gravity="center"  
    41.                 android:layout_marginLeft="10dp" />  
    42.             <TextView  
    43.                 android:layout_width="match_parent"  
    44.                 android:layout_height="wrap_content"  
    45.                 android:text="@string/xiaoxi"  
    46.                 android:textColor="@color/test_bg"  
    47.                 android:gravity="center"  
    48.                 android:textSize="30sp"  
    49.                 android:layout_marginTop="10dp"  
    50.                 android:layout_marginBottom="10dp" />  
    51.         </LinearLayout>  
    52.         <View  
    53.             android:layout_width="match_parent"  
    54.             android:layout_height="1dp"  
    55.             android:background="#999999" />  
    56.     </LinearLayout>  
    57.     <LinearLayout  
    58.         android:layout_width="fill_parent"  
    59.         android:layout_height="wrap_content"  
    60.         android:layout_below="@+id/linear2"  
    61.         android:id="@+id/linear4"  
    62.         android:orientation="vertical"  
    63.         android:clickable="true">  
    64.         <LinearLayout  
    65.             android:layout_width="match_parent"  
    66.             android:layout_height="wrap_content"  
    67.             android:orientation="horizontal">  
    68.             <ImageView  
    69.                 android:layout_width="wrap_content"  
    70.                 android:layout_height="wrap_content"  
    71.                 android:src="@drawable/school"  
    72.                 android:layout_gravity="center"  
    73.                 android:layout_marginLeft="10dp" />  
    74.             <TextView  
    75.                 android:layout_width="match_parent"  
    76.                 android:layout_height="wrap_content"  
    77.                 android:text="校园活动"  
    78.                 android:textSize="30sp"  
    79.                 android:textColor="#808080"  
    80.                 android:gravity="center"  
    81.                 android:layout_marginTop="10dp"  
    82.                 android:layout_marginBottom="10dp" />  
    83.         </LinearLayout>  
    84.         <View  
    85.             android:layout_height="1dp"  
    86.             android:layout_width="match_parent"  
    87.             android:background="#999999" />  
    88.     </LinearLayout>  
    89.     <LinearLayout  
    90.         android:orientation="vertical"  
    91.         android:layout_width="match_parent"  
    92.         android:layout_height="wrap_content"  
    93.         android:layout_below="@+id/linear4"  
    94.         android:clickable="true">  
    95.         <LinearLayout  
    96.             android:orientation="horizontal"  
    97.             android:layout_width="match_parent"  
    98.             android:layout_height="wrap_content">  
    99.             <ImageView  
    100.                 android:id="@+id/img1"  
    101.                 android:src="@drawable/taobao"  
    102.                 android:layout_gravity="center"  
    103.                 android:layout_height="wrap_content"  
    104.                 android:layout_width="wrap_content"  
    105.                 android:layout_marginLeft="10dp" />  
    106.             <TextView  
    107.                 android:text="@string/taobao"  
    108.                 android:textColor="@color/test_bg"  
    109.                 android:textSize="30sp"  
    110.                 android:layout_height="wrap_content"  
    111.                 android:layout_width="match_parent"  
    112.                 android:layout_marginTop="10dp"  
    113.                 android:layout_marginBottom="10dp"  
    114.                 android:gravity="center" />  
    115.         </LinearLayout>  
    116.     </LinearLayout>  
    117. </RelativeLayout>  

    xamarin android布局练习(2)

    看看效果图2

    代码如下:

    [html] view plain copy
    print?
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_height="match_parent"  
    4.     android:layout_width="match_parent"  
    5.     android:id="@+id/linear1"  
    6.     android:orientation="vertical">  
    7.     <LinearLayout  
    8.         android:layout_height="wrap_content"  
    9.         android:layout_width="match_parent"  
    10.         android:id="@+id/linear2"  
    11.         android:orientation="vertical"  
    12.         android:background="#dedede">  
    13.         <TextView  
    14.             android:layout_height="wrap_content"  
    15.             android:layout_width="match_parent"  
    16.             android:textColor="#808080"  
    17.             android:textSize="20dp"  
    18.             android:text="如何使用xamarin布局练习"  
    19.             android:layout_marginTop="10dp"  
    20.             android:layout_marginBottom="10dp" />  
    21.         <RelativeLayout  
    22.             android:layout_height="wrap_content"  
    23.             android:layout_width="match_parent"  
    24.             android:id="@+id/relative1">  
    25.             <ImageView  
    26.                 android:id="@+id/imgCenter"  
    27.                 android:layout_height="100dp"  
    28.                 android:layout_width="100dp"  
    29.                 android:layout_centerInParent="true"  
    30.                 android:src="@drawable/taobao" />  
    31.             <ImageView  
    32.                 android:id="@+id/imgLeft"  
    33.                 android:layout_alignParentLeft="true"  
    34.                 android:layout_height="100dp"  
    35.                 android:layout_width="100dp"  
    36.                 android:src="@drawable/taobao1" />  
    37.             <ImageView  
    38.                 android:id="@+id/imgRight"  
    39.                 android:layout_alignParentRight="true"  
    40.                 android:layout_height="100dp"  
    41.                 android:layout_width="100dp"  
    42.                 android:src="@drawable/taobao1" />  
    43.         </RelativeLayout>  
    44.         <LinearLayout  
    45.             android:layout_height="wrap_content"  
    46.             android:layout_marginTop="10dp"  
    47.             android:layout_width="match_parent"  
    48.             android:orientation="horizontal"  
    49.             android:id="@+id/relative2">  
    50.             <TextView  
    51.                 android:textColor="#999999"  
    52.                 android:textSize="15dp"  
    53.                 android:text="手机腾讯网"  
    54.                 android:id="@+id/txt1"  
    55.                 android:layout_height="wrap_content"  
    56.                 android:layout_width="wrap_content" />  
    57.             <TextView  
    58.                 android:textColor="#999999"  
    59.                 android:textSize="15dp"  
    60.                 android:text="评论  89"  
    61.                 android:layout_height="wrap_content"  
    62.                 android:layout_width="wrap_content"  
    63.                 android:layout_gravity="right" />  
    64.         </LinearLayout>  
    65.         <View  
    66.             android:layout_height="1dp"  
    67.             android:layout_width="match_parent"  
    68.             android:background="#808080" />  
    69.     </LinearLayout>  
    70.     <LinearLayout  
    71.         android:layout_height="wrap_content"  
    72.         android:layout_width="match_parent"  
    73.         android:id="@+id/linear21"  
    74.         android:orientation="vertical"  
    75.         android:background="#dedede"  
    76.         android:layout_marginTop="10dp">  
    77.         <TextView  
    78.             android:layout_height="wrap_content"  
    79.             android:layout_width="match_parent"  
    80.             android:textColor="#808080"  
    81.             android:textSize="20dp"  
    82.             android:text="如何使用xamarin布局练习2"  
    83.             android:layout_marginTop="10dp"  
    84.             android:layout_marginBottom="10dp" />  
    85.         <RelativeLayout  
    86.             android:layout_height="wrap_content"  
    87.             android:layout_width="match_parent"  
    88.             android:id="@+id/relative11">  
    89.             <ImageView  
    90.                 android:id="@+id/imgCenter1"  
    91.                 android:layout_height="100dp"  
    92.                 android:layout_width="100dp"  
    93.                 android:layout_centerInParent="true"  
    94.                 android:src="@drawable/taobao" />  
    95.             <ImageView  
    96.                 android:id="@+id/imgLeft1"  
    97.                 android:layout_alignParentLeft="true"  
    98.                 android:layout_height="100dp"  
    99.                 android:layout_width="100dp"  
    100.                 android:src="@drawable/taobao1" />  
    101.             <ImageView  
    102.                 android:id="@+id/imgRight1"  
    103.                 android:layout_alignParentRight="true"  
    104.                 android:layout_height="100dp"  
    105.                 android:layout_width="100dp"  
    106.                 android:src="@drawable/taobao1" />  
    107.         </RelativeLayout>  
    108.         <LinearLayout  
    109.             android:layout_height="wrap_content"  
    110.             android:layout_marginTop="10dp"  
    111.             android:layout_width="match_parent"  
    112.             android:orientation="horizontal"  
    113.             android:id="@+id/relative21">  
    114.             <TextView  
    115.                 android:textColor="#999999"  
    116.                 android:textSize="15dp"  
    117.                 android:text="手机腾讯网"  
    118.                 android:id="@+id/txt11"  
    119.                 android:layout_height="wrap_content"  
    120.                 android:layout_width="wrap_content" />  
    121.             <TextView  
    122.                 android:textColor="#999999"  
    123.                 android:textSize="15dp"  
    124.                 android:text="评论  89"  
    125.                 android:layout_height="wrap_content"  
    126.                 android:layout_width="wrap_content"  
    127.                 android:layout_gravity="right" />  
    128.         </LinearLayout>  
    129.     </LinearLayout>  
    130. </LinearLayout>  
    主要的关键点在于:relative布局,
    [html] view plain copy
    print?
    1. android:layout_alignParentLeft="true"  
    这个属性非常重要,在父容器中的对其方式,bool类型的。layout_alignParentLeft="true"在父容器中左对齐

    xamarin android布局练习(3)

    效果图:


    代码如下:

    [html] view plain copy
    print?
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_height="match_parent"  
    4.     android:layout_width="match_parent"  
    5.     android:id="@+id/relative"  
    6.     android:background="#dedede">  
    7.     <ImageView  
    8.         android:layout_height="64dp"  
    9.         android:layout_width="64dp"  
    10.         android:id="@+id/imgCenter"  
    11.         android:src="@drawable/taobao"  
    12.         android:layout_centerInParent="true" />  
    13.     <ImageView  
    14.         android:layout_height="64dp"  
    15.         android:layout_width="64dp"  
    16.         android:id="@+id/imgTop"  
    17.         android:src="@drawable/wangwang"  
    18.         android:layout_above="@+id/imgCenter"  
    19.         android:layout_centerHorizontal="true" />  
    20.     <ImageView  
    21.         android:layout_height="64dp"  
    22.         android:layout_width="64dp"  
    23.         android:id="@+id/imgRight"  
    24.         android:src="@drawable/suning"  
    25.         android:layout_toRightOf="@+id/imgCenter"  
    26.         android:layout_centerVertical="true" />  
    27.     <ImageView  
    28.         android:layout_height="64dp"  
    29.         android:layout_width="64dp"  
    30.         android:id="@+id/imgLeft"  
    31.         android:src="@drawable/suning"  
    32.         android:layout_toLeftOf="@+id/imgCenter"  
    33.         android:layout_centerVertical="true" />  
    34.     <ImageView  
    35.         android:layout_height="64dp"  
    36.         android:layout_width="64dp"  
    37.         android:id="@+id/imgBottom"  
    38.         android:src="@drawable/jingsong"  
    39.         android:layout_below="@+id/imgCenter"  
    40.         android:layout_centerHorizontal="true" />  
    41. </RelativeLayout>  

    关键点在于如何使用relative的各种对其方式



    xamarin android布局练习简单的登录(4)

    效果如下:
    只用了一个linear布局
    [html] view plain copy
    print?
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:orientation="vertical"  
    4.     android:layout_width="match_parent"  
    5.     android:layout_height="match_parent"  
    6.     android:background="@color/loginBgColor">  
    7.     <LinearLayout  
    8.         android:layout_height="wrap_content"  
    9.         android:layout_width="match_parent"  
    10.         android:id="@+id/linear1"  
    11.         android:orientation="vertical">  
    12.         <TextView  
    13.             android:id="@+id/txt"  
    14.             android:layout_height="wrap_content"  
    15.             android:layout_width="wrap_content"  
    16.             android:layout_marginTop="30dp"  
    17.             android:layout_marginBottom="30dp"  
    18.             android:layout_marginRight="30dp"  
    19.             android:layout_gravity="right"  
    20.             android:text="设备登录"  
    21.             android:textColor="@color/whiteColor"  
    22.             android:textSize="20dp" />  
    23.     </LinearLayout>  
    24.     <LinearLayout  
    25.         android:id="@+id/linear2"  
    26.         android:layout_height="wrap_content"  
    27.         android:layout_width="match_parent"  
    28.         android:orientation="vertical">  
    29.         <TextView  
    30.             android:id="@+id/txt2"  
    31.             android:layout_height="wrap_content"  
    32.             android:layout_width="wrap_content"  
    33.             android:textSize="30dp"  
    34.             android:textColor="@color/whiteColor"  
    35.             android:layout_gravity="center"  
    36.             android:text="LOGO"  
    37.             android:layout_marginTop="20dp"  
    38.             android:layout_marginBottom="20dp" />  
    39.     </LinearLayout>  
    40.     <LinearLayout  
    41.         android:id="@+id/linear3"  
    42.         android:layout_height="wrap_content"  
    43.         android:layout_width="match_parent"  
    44.         android:orientation="vertical"  
    45.         android:layout_marginLeft="20dp"  
    46.         android:layout_marginRight="20dp">  
    47.         <EditText  
    48.             android:id="@+id/txtUserName"  
    49.             android:background="@color/whiteColor"  
    50.             android:hint="请输入用户名"  
    51.             android:focusable="true"  
    52.             android:layout_width="match_parent"  
    53.             android:layout_height="50dp"  
    54.             android:textSize="20dp"  
    55.             android:textColor="#000000"  
    56.             android:paddingLeft="10dp"  
    57.             android:textCursorDrawable="@null" />  
    58.         <View  
    59.             android:layout_width="match_parent"  
    60.             android:layout_height="1dp"  
    61.             android:background="#dedede" />  
    62.         <EditText  
    63.             android:id="@+id/txtPassword"  
    64.           android:background="@color/whiteColor"  
    65.             android:hint="请输入密码1"  
    66.             android:textCursorDrawable="@null"  
    67.             android:inputType="textPassword"  
    68.             android:layout_width="match_parent"  
    69.             android:layout_height="50dp"  
    70.             android:textSize="20dp"  
    71.             android:paddingLeft="10dp"  
    72.             android:textColor="#000000" />  
    73.         <Button  
    74.             android:id="@+id/btnLogin"  
    75.             android:text="登录"  
    76.             android:layout_height="50dp"  
    77.             android:layout_width="match_parent"  
    78.             android:textColor="@color/whiteColor"  
    79.             android:background="#2894FF"  
    80.             android:textSize="20dp"  
    81.             android:paddingTop="5dp"  
    82.             android:paddingBottom="5dp"  
    83.             android:layout_marginTop="20dp" />  
    84.     </LinearLayout>  
    85.     <LinearLayout  
    86.         android:layout_height="wrap_content"  
    87.         android:layout_width="match_parent"  
    88.         android:orientation="horizontal"  
    89.         android:layout_marginLeft="20dp"  
    90.         android:layout_marginTop="10dp"  
    91.         android:id="@+id/linear5">  
    92.         <CheckBox  
    93.             android:id="@+id/checkbox_remeberUser"  
    94.             android:layout_height="30dp"  
    95.             android:layout_width="30dp"  
    96.             android:textColor="#336699"  
    97.             android:textColorHighlight="#336699" />  
    98.         <TextView  
    99.             android:id="@+id/remeberUser"  
    100.             android:layout_height="wrap_content"  
    101.             android:layout_width="wrap_content"  
    102.             android:text="记住该用户"  
    103.             android:textColor="#FFFFFF"  
    104.             android:textSize="16dp" />  
    105.     </LinearLayout>  
    106. </LinearLayout>  
原创粉丝点击