1.1、android:layout_weight="1"
两个控件设置为1可以将屏幕等分为两份,更改数值可以根据各自数值各占有屏幕的尺寸 (如3/2)button1占有屏幕5/3,button占有屏幕5/2.
1. 2、将button1 设置为 android:layout_width="0dp",android:layout_weight="1",button2部为
wrap_content可是实现宽度自适应。
二、隐藏系统标题栏2. 1.ActionBar 获取状态栏
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// 实现透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
setContentView(R.layout.activity_main);
//hide bar
ActionBar actionBar = getActionBar();
if (actionBar != null){
actionBar.hide();
}
init();
}
三、百分比布局
3.1.引入implementation ‘com.android.support:percent:25.2.0’
四、引入自定义控件4.1.创建布局 xml,内容自定义,
4.2.创建class并引入,继承LinearLayout或其他,实现TitleLayout方法
public class TitleLayout extends LinearLayout {
public TitleLayout(final Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.titlebar,this);
Button b1 = findViewById(R.id.b1);
Button b2 = findViewById(R.id.b2);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "back", Toast.LENGTH_SHORT).show();
}
});
}
}
4. 3.end 引入全名



