日韩性视频-久久久蜜桃-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ò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩欧美网站 | 777视频在线观看 | 操大爷影院 | 国产91精品久久久久 | 九九精品视频在线 | av免费视屏 | 强行侵犯视频在线观看 | 国产精品无码久久久久久 | 欧美性色19p | 韩日精品在线观看 | 99xav| 三区在线 | 亚洲中文字幕视频一区 | 日韩人妻一区二区三区蜜桃视频 | 亚洲最大av在线 | 欧美超逼视频 | 日韩成人在线看 | 国产一级做a爰片在线看免费 | 男人的天堂97 | 天堂网在线资源 | 国产三级精品在线观看 | 91在线观看 | 亚洲videos| 在线一区二区三区四区五区 | 台湾男男gay做爽爽的视频 | avtt香蕉久久| 国产男女猛烈无遮挡免费视频动漫 | 亚洲熟女少妇一区二区 | 国产亚洲精品成人 | 国产精品无码久久久久久 | 日本在线免费看 | 性色欲网站人妻丰满中文久久不卡 | 秋霞一区 | 久久综合日本 | 亚洲va天堂va欧美ⅴa在线 | 在线看a网站 | 草草影院网址 | 久久久久久久久久久国产 | 免费大片在线观看www | 免费看欧美黑人毛片 | 国产免费黄色大片 | 久久免费视频网 | 成人免费性生活视频 | 各处沟厕大尺度偷拍女厕嘘嘘 | 熟妇高潮一区二区三区在线播放 | 啪啪综合| 污视频在线观看网站 | a级片免费看 | 久久久久亚洲av成人无码电影 | www,xxx69 japan| 色呦呦精品 | 天天摸天天干天天操 | 精品在线观看视频 | 打美女白嫩屁屁网站 | 日韩色在线观看 | 国产一区二区在线免费观看 | 欧美激情一区二区三区免费观看 | 午夜黄色福利 | 色午夜婷婷 | 国产精品久久久久久久久免费相片 | 小镇姑娘高清播放视频 | 国产黄色一级 | 日韩三级在线免费观看 | japanese21ⅹxx日本 | 午夜极品视频 | 欧美综合亚洲图片综合区 | 日本一区二区高清免费 | 亚洲一区免费电影 | 五月婷婷一区二区 | 国产精品久久777777毛茸茸 | 双女主黄文 | 秋霞在线一区 | 久国产视频 | 国产欧美亚洲一区 | 亚洲射吧 | 久久久精品在线 | 无码任你躁久久久久久久 | 直接看毛片| 亚洲欧美成人一区二区 | 蜜桃久久久aaaa成人网一区 | 成年人一级黄色片 | 日本三级456 | 国产日韩精品电影 | 亚洲人成7777| 最新中文字幕在线观看视频 | 屁屁影院一区二区三区 | 国产大学生自拍视频 | 天天爽天天操 | 午夜精品视频一区二区三区在线看 | 波多野结衣三级视频 | 欧美日韩一区二区三 | 国产精品视频一区二区三区不卡 | 久久精品视频一区二区三区 | 伊人网综合在线 | 国产免费一区二区三区网站免费 | 亚洲精品视频中文字幕 | 中文字幕免费在线观看 | 国产精品视频入口 | 亚洲欧美日韩精品久久亚洲区 |