Andriodjie——自定义头布局
来源:互联网 发布:淘宝游戏交易平台网址 编辑:程序博客网 时间:2024/05/16 04:58
import android.content.Context;import android.util.AttributeSet;import android.view.LayoutInflater;import android.widget.Button;import android.widget.LinearLayout;import android.widget.TextView;import com.example.moni_01.R;public class MyTitleView extends LinearLayout{ private Button bt_left; //返回按钮 private TextView tv_title; //标题名称 private Button bt_right; //查询按钮 public MyTitleView(Context context) { this(context,null); } public MyTitleView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.title, this, true); bt_left = (Button) findViewById(R.id.bt_left); tv_title = (TextView) findViewById(R.id.tv_title); bt_right = (Button) findViewById(R.id.bt_right); } //自定义接口点击事件 public void setOnRigltClickListener(OnClickListener listener){ bt_right.setOnClickListener(listener); } public void setOnLeftClickListener(OnClickListener listener){ bt_left.setOnClickListener(listener); }}
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private MyTitleView mview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);initView();
mview = (MyTitleView) findViewById(R.id.include); mview.setOnRigltClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(MainActivity.this,User.class); startActivity(intent); } }); }//引用MyTitleView方法
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:mine="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.moni_01.view.MyTitleView android:id="@+id/include" android:layout_width="match_parent" android:layout_height="wrap_content"/></RelativeLayout>//MyTitleView的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:mine="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/ll" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentTop="true" android:background="#d5d5c9" android:orientation="horizontal"> <Button android:id="@+id/bt_left" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="返回" /> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="3" android:gravity="center" android:text="那些花儿" android:textColor="#494444" android:textSize="30sp" /> <Button android:id="@+id/bt_right" android:layout_width="15dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/aa" /> </LinearLayout></RelativeLayout>
阅读全文
0 0
- Andriodjie——自定义头布局
- andriodjie——recycleview
- Andriodjie——登陆注册展示商品
- Andriodjie——画圆3秒跳转
- Andriodjie——OKhttp拦截器
- andriodjie——实现小圆点
- 自定义控件之——自动显示隐藏头布局
- Andriodjie——RecyclerView点击查看商品详情
- Andriodjie——简单的购物车全选反选
- Andriodjie——二级列表实现购物车
- andriodjie——MVP加RecycleView简单展示
- andriodjie——xRecyclerView网络获取数据简单实现
- Andriodjie——二级列表实现购物车
- 自定义GridView 实现加载头布局
- 自定义头布局下拉变大的ScrollView
- ListView添加头布局的自定义控件
- Andriodjie——欢迎页3秒跳转到主页+banner图片轮播
- andriodjie——mvp展示拦截器传来的数据跳转购物车
- Spring框架学习之高级依赖关系配置(一)
- 使用appendChild(),insertBefore()的一个小问题
- 欢迎使用CSDN-markdown编辑器
- Elasticsearch使用过程中问题总汇(一)
- AutoLayout 安卓全新的适配方式
- Andriodjie——自定义头布局
- Text Autosizer&&解决移动端网页文本字体怪异增大问题
- Oracle:对行进行分组GROUP BY
- 51nod 1416两点问题(DFS)
- Excel根据批注的内容自动调整批注大小
- [CVPR2017] CFNet 论文解读
- python网络爬虫笔记之信息提取
- 编译原理---编译
- jQuery入门和响应式布局3种方法