Android studio 简易流式布局
**
Android studio 简易流式布局
**
欢迎使用Android studio编辑器
你好! 这是你第一次使用 Android studio编辑器 所展示的欢迎页。如果你想学习如何使用Android studio编辑器, 可以仔细阅读这篇文章,了解一下Android studio的基本语法知识。
自定义View
package com.example.dome1.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.dome1.R;
public class MyView extends ViewGroup{
private final Context mContext;
public MyView(Context context, AttributeSet attrs) {super(context, attrs);this.mContext = context;
}@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {//获取子控件int childCount = getChildCount();//初始化操作//间距int span=20;int top=0;int btoom=0;;int left=0;int right=0;//根据子控件循环for (int i=0;i<childCount;i++){//获取每个子控件View childAt = getChildAt(i);//测量子控件的宽高childAt.measure(0,0);//获取子控件的测量宽高int measuredWidth = childAt.getMeasuredWidth();int measuredHeight = childAt.getMeasuredHeight();left=right+span;right=left+measuredWidth;int width = getWidth();if (right>width){left=span;top=btoom+span;}right=left+measuredWidth;btoom=top+measuredHeight;childAt.layout(left,top,right,btoom);}}
public void GetName(String name){TextView textView = new TextView(mContext);//设置文本的颜色textView.setTextColor(Color.RED);//设置文本的大小textView.setTextSize(20);//设置文本的内容textView.setText(name);//添加到视图上显示addView(textView);
}
}
Activity中引用
public class MainActivity extends BaseActivity {
private RecyclerView recy;
private EditText et_name;
private TextView bt_name;
private MyView myView;@Override
protected void initData() {bt_name.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String name = et_name.getText().toString().trim();//进行判空if (name.isEmpty()){Toast.makeText(MainActivity.this, "内容不能为空", Toast.LENGTH_SHORT).show();}else {myView.GetName(name);mPresenter.onPresenter("http://172.17.8.100/small/commodity/v1/findCommodityByKeyword?keyword="+ URLEncoder.encode(name) +"&page=1&count=5");}}});recy.setLayoutManager(new StaggeredGridLayoutManager(2,RecyclerView.VERTICAL));}
Android studio 简易流式布局相关推荐
- Android自定义控件之流式布局
效果图: 一.首先创建我 们的自定义流式布局 public class FlowLayoutView extends ViewGroup {public FlowLayoutView(Context ...
- android自定义流式布局思路,Android 自定义控件基础-流式布局
什么是流式布局?其实我们在平时遇到过,只是有可能叫不出它的名字. 如图: 如上图,就是一个流式布局的样式. &esmp;这里,将记录一下怎么实现这个功能.其实实现这个功能的方法,就是自定义Vi ...
- Android 实现FlowLayout流式布局(热门标签)
先上效果图: 接着看代码实现: public class FlowLayout extends ViewGroup {protected DataSetObserver mDataSetObserve ...
- Android自定义组合布局,Android 流式布局 + 自定义组合控件
自定义组合控件 package yanjupeng.bawei.com.day09.two; import android.content.Context; import android.util.A ...
- Android 自动换行流式布局的RadioGroup
用法 使用FlowRadioGroup代替RadioGroup import android.content.Context; import android.util.AttributeSet; im ...
- Flutter: 弹性布局Flex(Expanded)、流式布局Wrap、Flow
用Android原生实现流式布局[实现例如app的很多标签]需要自定义View继承自ViewGroup,然后代码量也不小. 相关自定义View实现流式布局,请参考这位老兄的博客: https://bl ...
- 自定义 FlowLayout流式布局搜索框 加 GreenDao存取搜索记录,使用RecyclerView展示
输入框布局的shape <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android ...
- 流式布局的RadioGroup
当我们使用RadioGroup时,如果文字信息较多的时候不会展示出来..这个时候我们需要重新对RadioGroup进行处理,当信息过多的时候自动换行 也就是大家所说的流布局样式的RadioGroup ...
- android 流失布局,Android使用RecyclerView实现流式布局的注意事项
纯手打,不喜勿喷 long may the sun shine 众所周知,Android开发中Recycleview的功能十分强大,可以实现各种炫酷的效果,今天我根据最近开发的一个项目简要说下流式布局 ...
- Android自定义流式布局-FlowLayout
很多App在搜索页时都有对热门标签的一个排列,而Android官方没有对应的布局控件,所以自己写了一个流式布局(也称标签布局)--FlowLayout. 为了大家使用的方便,没有添加自定义属性,所以需 ...
最新文章
- “中文版GPT-3”来了:会算术、可续写红楼梦,用64张V100训练了3周
- 什么是QoS技术?—Vecloud微云
- java内部类的作用
- 容联雷辉:视频系统由标清进入到移动高清时代
- 与时共舞,力求变革【我眼中的戴尔转型】
- FTC再度对Facebook提起反垄断诉讼,要求其出售Instagram和WhatsApp
- 为什么普通红包自己不能领_腾讯为推广新游王牌战士而豪撒千金?快去看看你能不能领红包...
- FTP+SSL(加密的ftp)
- 【毕业设计源码】基于SSM的小程序任务调度管理信息系统设计与实现
- 一文读懂声纹采集、声纹识别、声纹数据库系统等声纹识别技术在公安业务领域的应用场景
- 握奇ukey没证书_关于中国银行企业网银USBKEY常见问题及解决方法指引140523.doc
- nc65右键生成菜单_NC常见问题处理
- itunes没法ipa_上传了ipa但iTunes Connect没有构建版本问题
- Pandas DataFrame 使用技巧
- 18_一文总结Flask语法
- 使用Unity编写传统ARPG游戏人物操作方式(二)
- react等 一些视频学习网址
- VLAN 、PVLAN
- 香港大学赵恒爽老师招收计算机视觉博士/博士后/研究助理
- modbus信号与AO AI DO DI的区别是什么