日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

重温7 布局相关

發布時間:2023/12/2 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 重温7 布局相关 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、LinearLayout

可以在控件中使用:

android:layout_weight="1" android:layout_width="0dp"設置控件占屏幕寬度,上表示占屏幕1/2。

2、TableLayout

<TableLayout android:stretchColums="1" ...>上指定為1表示拉伸第2列,指定為0表示拉伸第1列

<Button android:layout_span="2" .../>指定控件所占列數,上表示占兩列的空間。

3、創建自定義控件 XML、java、include標簽

java:

加載布局后

LayoutInflater.from(context).inflate(R.layout.title, this);

優:可以在代碼中設置點擊事件

package com.example.comeonlinearlayouttitle;import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.widget.LinearLayout; import android.widget.Button; import android.view.View; import android.annotation.SuppressLint; import android.app.Activity; @SuppressLint("NewApi") public class TitleLayout extends LinearLayout{public TitleLayout(Context context) {super(context);// TODO Auto-generated constructor stub}public TitleLayout(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stubLayoutInflater.from(context).inflate(R.layout.title, this);Button back_btn = (Button)findViewById(R.id.back);back_btn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View view){//Context android.view.View.getContext()//Returns the context the view is running in((Activity) getContext()).finish();}});}public TitleLayout(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}} 在XML中使用

<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"><com.example.comeonlinearlayouttitle.TitleLayout android:layout_height="wrap_content"android:layout_width="match_parent"></com.example.comeonlinearlayouttitle.TitleLayout></LinearLayout> <!-- <include layout="@layout/title"/> -->在XML中寫,使用include標簽

<include layout="@layout/title_layout"/>
完整代碼在:https://github.com/HiSunny/ComeOnTitle.git

總結

以上是生活随笔為你收集整理的重温7 布局相关的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。