Android界面设计

从继承关系来看,所有组件继承自View。容器也是继承自View,它能容纳别的View。

所有容器继承自ViewGroup。包括

FrameLayout, LinearLayout, RelativeLayout, SlidingDrawer , AbsoluteLayout, AdapterView

Activity中绑定容器的方法 setContentView(linearLayout)

 

获取activity最顶层的view
findViewById(android.R.id.content);
getWindow().getDecorView();
一般是viewgroup

2018-08-28

以为View就是类似于h5里面的div,然后用View去包TextView,总是报错,后来才知道View就是一个组件,不是容器。

View在线性布局中有一个好处,就是占位,

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">
        <View
            android:layout_width="0dp"
            android:layout_weight="10"
            android:layout_height="0dp"></View>
        <TextView
            android:layout_width="50dp"
            android:background="@color/red"
            android:layout_weight="1"
            android:layout_marginRight="0dp"
            android:layout_height="50dp" />
    </LinearLayout>

比如这个,TextView我想右边排,直接右边排是不行的,要在它前边放一个VIew作填充,把它的权重设低点,TextView权重设高点就行了。

 原来这个dp和网页的px一样的,我的360N5手机,都是360px(dp)的宽。

 在LinearLayout中

android:layout_marginBottom没效果,要用android:layout_gravity="bottom"(重心)
icon图标还是要贴边切,并且透明png
如果是正方形,可通过
android:padding="5dp"改变值,控制它居中显示的大小。

2018-08-29

相对布局中,这两个属性要同时设置好。

android:layout_alignParentRight="true"
android:layout_marginRight="0dp"

FrameLayout布局

以左上角为坐标,不断地把view叠起来。如果后面的没有档到前面的,前面的也会显示出来。

从xml里读布局文件并实例化。

inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(
R.layout.activity_alarm_message_item, null);

 

posted on 2014-01-01 11:06  angelshelter  阅读(250)  评论(0编辑  收藏  举报

导航