Android Studio 系统学习心得第一天
一 新建的activity自带的xml文件用的是约束性布局,怎么改?
选中第二行的 android.support.constraint.ConstraintLayout删除,然后打上你想用的布局文件,记住不要删除前面的<,这样下方的对应约束会自己变。
二 LinerLayout相关
属性1:layout_margin
外边距:布局或控件距离外部元素多少
单边距:eg:marginLeft
属性2:layout_padding
内边距:布局或控件距离内部元素多少
属性3:layout_weight
官方解释:权重
假设两个子空间weight都为1,剩余部分平分
实例:
对应代码:
<LinearLayout
android:layout_width="300dp"
android:layout_height="200dp"
android:background="#000000"
android:padding="20dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000"
android:text="TextView" />
</LinearLayout>