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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android自定义组合布局,Android 流式布局 + 自定义组合控件

發(fā)布時(shí)間:2024/7/19 Android 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android自定义组合布局,Android 流式布局 + 自定义组合控件 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

自定義組合控件

package yanjupeng.bawei.com.day09.two;

import android.content.Context;

import android.util.AttributeSet;

import android.util.Log;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.EditText;

import android.widget.LinearLayout;

import android.widget.TextView;

import yanjupeng.bawei.com.day09.R;

public class TwoLayout extends LinearLayout {

public TextView textView;

public EditText editText;

public TwoLiu twoLiu;

public LinearLayout linearLayout;

public TwoLayout(Context context) {

super(context);

}

public TwoLayout(final Context context, AttributeSet attrs) {

super(context, attrs);

View view = LayoutInflater.from(context).inflate(R.layout.twolayout , this);

textView = view.findViewById(R.id.two_text_id);

editText = view.findViewById(R.id.two_ed_id);

twoLiu = view.findViewById(R.id.two_liu_id);

linearLayout = view.findViewById(R.id.two_layout_id);

textView.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

String string = editText.getText().toString();

Log.e("tag" , "textView ====="+string );

final TextView textView = new TextView(context);

textView.setTag(string);

textView.setText(string);

textView.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Log.e("tag" , "textView =====" + textView.getTag().toString());

}

});

twoLiu.addView(textView);

linearLayout.requestLayout();

}

});

}

public TwoLayout(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

}

}

xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/two_layout_id"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:id="@+id/two_ed_id"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

/>

android:id="@+id/two_text_id"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="搜索"

android:textSize="20sp"

android:background="#4ff"

/>

android:id="@+id/two_liu_id"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#ccc">

activity

package yanjupeng.bawei.com.day09.two;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import yanjupeng.bawei.com.day09.R;

public class TwoActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_two);

}

}

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".two.TwoActivity">

android:layout_width="match_parent"

android:layout_height="match_parent">

流式布局

package yanjupeng.bawei.com.day09.two;

import android.content.Context;

import android.util.AttributeSet;

import android.util.Log;

import android.view.ViewGroup;

public class TwoLiu extends ViewGroup {

public int mLeftMargin = 20;

public int mTopMargin = 20;

public TwoLiu(Context context) {

super(context);

}

public TwoLiu(Context context, AttributeSet attrs) {

super(context, attrs);

}

public TwoLiu(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

Log.e("tag" , "onMeasure");

measureChildren(widthMeasureSpec ,heightMeasureSpec);

int leftMargin = mLeftMargin;

int topMargin = mTopMargin;

int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);

int modelWidth = MeasureSpec.getMode(widthMeasureSpec);

int sizeHeigth = MeasureSpec.getSize(heightMeasureSpec);

int modelHeigth = MeasureSpec.getMode(heightMeasureSpec);

switch (modelHeigth){

case MeasureSpec.AT_MOST:

int measuredHeight = 0 ;

for (int j = 0 ; j < getChildCount() ; j ++){

int measuredWidth = getChildAt(j).getMeasuredWidth();

measuredHeight = getChildAt(j).getMeasuredHeight();

if (leftMargin + measuredWidth + mLeftMargin > getMeasuredWidth()){

leftMargin = mLeftMargin;

topMargin += measuredHeight + mTopMargin;

}

leftMargin += measuredWidth + mLeftMargin;

}

topMargin += measuredHeight + mTopMargin;

break;

}

setMeasuredDimension(sizeWidth , topMargin);

}

@Override

protected void onLayout(boolean changed, int l, int t, int r, int b) {

Log.e("tag" , "onLayout");

int leftMargin = mLeftMargin;

int topmargin = mTopMargin;

for (int j = 0 ; j < getChildCount() ; j ++){

int measuredHeight = getChildAt(j).getMeasuredHeight();

int measuredWidth = getChildAt(j).getMeasuredWidth();

if (leftMargin + measuredWidth + mLeftMargin > getWidth()){

leftMargin = mLeftMargin;

topmargin += measuredHeight + mTopMargin;

getChildAt(j).layout(leftMargin , topmargin , measuredWidth + leftMargin , measuredHeight + topmargin );

}else {

getChildAt(j).layout(leftMargin , topmargin , measuredWidth + leftMargin ,measuredHeight + topmargin );

}

leftMargin += measuredWidth + mLeftMargin;

}

}

}

標(biāo)簽:控件,自定義,int,context,import,Android,leftMargin,public,android

來(lái)源: https://blog.csdn.net/qq_42886907/article/details/89064858

總結(jié)

以上是生活随笔為你收集整理的Android自定义组合布局,Android 流式布局 + 自定义组合控件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 重口变态虐黄网站 | 国产做爰免费观看视频 | 国产精品视频网址 | 国产亚洲天堂网 | 中文字幕视频免费观看 | 一区二区精彩视频 | 国产精品天天看 | 在线一区二区三区视频 | 国产欧美日本在线 | av永久免费在线观看 | 日本极品少妇 | 毛片毛片毛片毛片毛片毛片毛片 | 秋霞午夜 | 色亚洲欧美 | 一区二区久久精品66国产精品 | 中文字幕免费在线视频 | 国产精品亚洲色图 | 亚洲一二三级 | 成人黄色在线看 | 免费成人高清在线视频 | 欧美韩日 | 精品人妻一区二区三区日产乱码 | 欧美成人专区 | 国产在线免费视频 | 日本二三区 | 激情久久中文字幕 | 久久影院午夜理论片无码 | 四虎影视网| 香蕉久久视频 | 日本视频在线免费 | 亚洲视频一区二区三区在线观看 | 日本久久片 | 欧美精品一区二区久久婷婷 | 日本aaaa| 麻豆视频国产 | 骚婷婷| 奇米影视在线播放 | 在线免费观看国产视频 | 视频黄色免费 | 国产ts人妖调教重口男 | 色91av | 奇米777色 | 精品国产美女 | 激情青青草 | 91 色 | 国产精品调教视频 | 性生交大片免费看狂欲 | 天天射日日操 | 曰本黄色大片 | 东京热无码av一区二区 | 日本一本久草 | 免费看黄色片视频 | 特大黑人巨人吊xxxx | 91一区二区| 欧美一区二区三区久久成人精品 | 黑人毛片网站 | 日本一区二区高清视频 | 国产精品一品二区三区的使用体验 | 97自拍视频在线 | 亚洲淫片 | 精品免费囯产一区二区三区 | 性生交大片免费看3p | 福利一区福利二区 | 欧美jizz欧美性大全 | 人妻熟女一区 | 国产日韩欧美在线观看视频 | 无码一区二区三区在线 | 永久免费毛片 | 狠狠五月天 | 蜜桃视频在线观看www | 欧美视频一区在线观看 | 青草草在线观看 | 国产精品videossex国产高清 | 最新毛片基地 | www.色播 | 国产真实乱在线更新 | 超碰狠狠干 | 四虎永久免费 | 国产美女无遮挡永久免费 | 精品熟妇无码av免费久久 | 欧洲亚洲一区二区 | 亚洲天天干 | 好邻居韩国剧在线观看 | 懂色av一区二区三区在线播放 | av私库 | 色呦呦在线 | 日日草天天干 | 91精品国产闺蜜国产在线闺蜜 | 五月婷婷天 | 日韩美女久久 | 国产精品爱啪在线线免费观看 | 夜夜se | 免费在线观看网址 | 亚洲AV蜜桃永久无码精品性色 | 欧美日韩精品 | 免费看国产精品 | 成人手机视频在线观看 | 青青草免费在线视频 | 欧美亚洲综合在线 |