- 相对布局管理器使用
<?xml version="1.0" encoding="utf-8"?>
<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="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:background="@mipmap/kucaiba"
tools:context=".MainActivity">
<!-- android:gravity="center"-->
<!-- android:ignoreGravity="@id/user"-->
<!--tools:context 指定 activity 不会被打包到 apk-->
<!-- android:gravity 组件的摆放位置 android:ignoreGravity 不受前面控制 -->
<!-- RelativeLayout.layoutParams -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="发现有新版本,您想现在安装吗?"
android:id="@+id/text1"
/>
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_below="@id/text1"-->
<!-- android:text="mm"-->
<!-- android:id="@+id/mm"-->
<!-- />-->
<!-- android:layout_alignRight="@id/text1" -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/text1"
android:text="以后再说"
android:id="@+id/btnCancel"
/>
<!-- android:layout_toLeftOf="@id/btnCancel" -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/text1"
android:text="现在更新"
android:id="@+id/btnUpdate"
/>
</RelativeLayout>
- LinearLayout
- FrameLayout 主要是用于 层级叠加
两个重要属性 android:foreground android:foregroundGravity right|bottom - GridLayout
android:columnCount="6"
android:layout_columnSpan="4"
android:layout_column="1"
android:layout_row="0"
##嵌套布局管理器
嵌套规则
5. 只能有一个 根布局管理器
6.根布局管理必须包含xmlns属性
7.不能嵌套太深 否则影响性能
#单选框
RadioGroup getChildCount()
RadioButton idChecked()
#复选框
CheckBox
#日期选择器
DatePicker Calendar
#时间选择器
TimePicker setIs24HourView(true)
#计时器
Chronometer format
setBase
setOnChronometerTickListener
start
stop
#倒计时
final TextView textView = new TextView(MainActivity.this);
textView.setText("60");
textView.setTextSize(45);
textView.setTextColor(getResources().getColor(R.color.colorPrimary));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.myLinearLayout);
linearLayout.addView(textView);
textView.setGravity(Gravity.RIGHT);
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
Log.i("info", "seconds remaining: " + millisUntilFinished / 1000);
//ch.setText("" +( millisUntilFinished / 1000) );
textView.setText("" +( millisUntilFinished / 1000 - 1));
}
public void onFinish() {
Log.i("info", "done!");
}
}.start();