Open Theoneee opened 5 years ago
addTopBarBackBtn 是调用了 addLeftBackImageButton?
@ @cgspine 嗯嗯,mTopLayout.addLeftBackImageButton().setOnClickListener。 这个
if (params == null) {
params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
if(mLeftLastViewId != -1)
params.addRule(RelativeLayout.RIGHT_OF,mLeftLastViewId);
if(mRightLastViewId != -1)
params.addRule(RelativeLayout.LEFT_OF,mRightLastViewId);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
mTopLayout.addRightTextButton("搜索", R.id.topbar_right_1).setOnClickListener(this);
addTopBarBackBtn();
editText = (EditText) getView(R.layout.simple_edit_text);
mTopLayout.setCenterView(editText);
注意一定先初始化左右两边。中间留在最后。不然得到的id还是为-1。
亲测可以。
mTopLayout.addRightTextButton("搜索", R.id.topbar_right_1).setOnClickListener(this);
addTopBarBackBtn();
editText = (EditText) getView(R.layout.simple_edit_text);
RelativeLayout.LayoutParams params = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF,R.id.qmui_topbar_item_left_back);
params.addRule(RelativeLayout.LEFT_OF,R.id.topbar_right_1);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
mTopLayout.addView(editText,params);
按理来说这样写也是可以的。但是这里的addView()是QMUITopBarLayout执行的,而不是QMUITopBar。。所以那些规则设置了毫无作用。最好的还是我上面写的那样吧。少点代码。
我想实现这样的效果:
然后我的代码是:
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/search_bg_corner"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="@dimen/dp_10"
android:paddingBottom="@dimen/dp_10"
android:textSize="@dimen/sp_14"
android:hint="@string/search_hint"/>
`addTopBarBackBtn();
View view = getView(R.layout.custom_search_layout);
mTopLayout.setCenterView(view);
`出现的结果是:
然后改成这样子:
addTopBarBackBtn();
View view = getView(R.layout.custom_search_layout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF,R.id.qmui_topbar_item_left_back);
params.addRule(RelativeLayout.CENTER_VERTICAL);
mTopLayout.addView(view,params);
`结果是这样的:
大佬教一下怎么写才能是那样的效果啊。