10新建群聊布局的完成

最终实现的效果如下图:


首先是标题栏的实现:


使用的是相对布局,指定标题栏的高度和颜色背景:

  android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_top_bar"
        android:background="@color/common_top_bar_blue"

中间的文本使用了属性:


android:layout_centerInParent="true"

右边的是按钮,我指定了他的背景为null,所以看起来像TextView,使用了属性:

 android:layout_alignParentRight="true"
            android:layout_centerVertical="true"


整体的布局文件为:

 <RelativeLayout
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_top_bar"
        android:background="@color/common_top_bar_blue" >

        <LinearLayout
            android:layout_width="45dp"
            android:layout_height="match_parent"
            android:background="@drawable/common_tab_bg"
            android:onClick="back" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="9dp"
                android:scaleType="centerInside"
                android:src="@drawable/our_group_back_on" />
        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="新建群聊"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <Button
            android:layout_width="70dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:onClick="save"
            android:text="@string/button_save"
            android:textColor="#fff"
            android:textSize="14sp" />
    </RelativeLayout>

下面是两个输入框:EditText,很明显,这不是原生的了:


最主要的是因为他们的背景更改了:让他们的背景引用了一个drawable文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@android:color/white" />

    <corners android:radius="5dp" />

    <stroke
        android:width="1dp"
        android:color="#cccccc" />

</shape>

指定形状为矩形,画笔的颜色,粗细,圆角半径等等属性。

第一个和第二个的大小不同是因为第一个的:

 android:singleLine="true"

而第二的:

android:lines="5"

下面带有CheckBox的实现:


  <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="39dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/button_normal_shape"
        >
        <TextView 
            android:layout_marginLeft="5dp"
            android:text="是否公开"
            android:textColor="#88000000"
            android:textSize="18sp"
            android:layout_gravity="center_vertical"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
        <CheckBox 
             android:id="@+id/cb_public"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="0"
             android:layout_gravity="center_vertical"
             android:background="@drawable/checkbox_bg_selector"
            />
        
    </LinearLayout>
    
    
     <LinearLayout 
          android:id="@+id/ll_open_invite"
        android:layout_width="match_parent"
        android:layout_height="39dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/button_normal_shape"
        >
        <TextView 
            android:layout_marginLeft="5dp"
            android:text="开放群成员邀请"
            android:textColor="#88000000"
            android:textSize="18sp"
            android:layout_gravity="center_vertical"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
        <CheckBox 
             android:id="@+id/cb_member_inviter"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="0"
             android:layout_gravity="center_vertical"
             android:background="@drawable/checkbox_bg_selector"
            />
        
    </LinearLayout>

使用了
 android:layout_weight="1"
这个属性指定了线性布局的除了CheckBox占据的空间外,其他都是TextView的。

//==========================================

本布局的整体为:

<LinearLayout 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:background="#f2f0eb"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_top_bar"
        android:background="@color/common_top_bar_blue" >

        <LinearLayout
            android:layout_width="45dp"
            android:layout_height="match_parent"
            android:background="@drawable/common_tab_bg"
            android:onClick="back" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="9dp"
                android:scaleType="centerInside"
                android:src="@drawable/our_group_back_on" />
        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="新建群聊"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <Button
            android:layout_width="70dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:onClick="save"
            android:text="@string/button_save"
            android:textColor="#fff"
            android:textSize="14sp" />
    </RelativeLayout>

    <EditText
        android:id="@+id/edit_group_name"
        android:layout_width="match_parent"
        android:layout_height="39dp"
        android:layout_margin="10dp"
        android:background="@drawable/button_normal_shape"
        android:hint="群聊名称"
        android:paddingLeft="5dp"
        android:singleLine="true"
        android:textSize="18sp" />

    <EditText
        android:id="@+id/edit_group_introduction"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/button_normal_shape"
        android:gravity="top"
        android:hint="群聊简介"
        android:lines="5"
        android:paddingLeft="5dp"
        android:paddingTop="5dp"
        android:textSize="18sp" />
    
    
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="39dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/button_normal_shape"
        >
        <TextView 
            android:layout_marginLeft="5dp"
            android:text="是否公开"
            android:textColor="#88000000"
            android:textSize="18sp"
            android:layout_gravity="center_vertical"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
        <CheckBox 
             android:id="@+id/cb_public"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="0"
             android:layout_gravity="center_vertical"
             android:background="@drawable/checkbox_bg_selector"
            />
        
    </LinearLayout>
    
    
     <LinearLayout 
          android:id="@+id/ll_open_invite"
        android:layout_width="match_parent"
        android:layout_height="39dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/button_normal_shape"
        >
        <TextView 
            android:layout_marginLeft="5dp"
            android:text="开放群成员邀请"
            android:textColor="#88000000"
            android:textSize="18sp"
            android:layout_gravity="center_vertical"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
        <CheckBox 
             android:id="@+id/cb_member_inviter"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="0"
             android:layout_gravity="center_vertical"
             android:background="@drawable/checkbox_bg_selector"
            />
        
    </LinearLayout>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

</LinearLayout>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值