第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

右Button跑到左邊并且覆蓋左Button

老師,為什么我右邊的Button跑到左邊去了,并且覆蓋了左Button?

正在回答

2 回答

rightParams.addRule(RelativeLayout.ALIGN_RIGHT,TRUE);這一局里面不能填A(yù)LIGN_RIGHT,要填A(yù)LIGN_END.不要問為什么,我也不知道.理論上面,后者是為了防止一些國家右邊為先而設(shè)置的,但是前者的設(shè)置其實也行啊

0 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//58f9b4310001278e02590430.jpg

TOPbar.java/代碼

public class Topbar extends RelativeLayout{

private Button leftButton,rightButton;

private TextView tvTitle;

private int leftTextColor;

private Drawable leftBackground;

private String leftText;

private int rightTextColor;

private Drawable rightBackground;

private String rightText;

private float titleTextSize;

private int titleTextColor;

private String title;

private LayoutParams leftParams,rightParams,titleParams;

private topbarClickListener listener;

public interface topbarClickListener{

public void leftClick();

public void rightClick();

}

public void setOnTopbarClickListener(topbarClickListener listener){

this.listener =listener;

}

public Topbar(Context context, AttributeSet attrs) {

super(context, attrs);

TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.Topbar);

leftTextColor = ta.getColor(R.styleable.Topbar_leftTextColor,0 );

leftBackground = ta.getDrawable(R.styleable.Topbar_leftBackground);

leftText = ta.getString(R.styleable.Topbar_leftText);

rightTextColor = ta.getColor(R.styleable.Topbar_rightTextColor,0 );

rightBackground = ta.getDrawable(R.styleable.Topbar_rightBackground);

rightText = ta.getString(R.styleable.Topbar_rightText);

titleTextSize = ta.getDimension(R.styleable.Topbar_titleTextSize, 0);

titleTextColor = ta.getColor(R.styleable.Topbar_titleTextColor, 0);

title = ta.getString(R.styleable.Topbar_title);

ta.recycle();

leftButton = new Button(context);

rightButton = new Button(context);

tvTitle = new TextView(context);

leftButton.setTextColor(leftTextColor);

leftButton.setBackground(leftBackground);

leftButton.setText(leftText);

rightButton.setTextColor(rightTextColor);

rightButton.setBackground(rightBackground);

rightButton.setText(rightText);

tvTitle.setTextColor(titleTextColor);

tvTitle.setTextSize(titleTextSize);

tvTitle.setText(title);

tvTitle.setGravity(Gravity.CENTER);

setBackgroundColor(0xFFF59563);

leftParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

leftParams.addRule(RelativeLayout.ALIGN_LEFT,TRUE);

addView(leftButton,leftParams);

rightParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

rightParams.addRule(RelativeLayout.ALIGN_RIGHT,TRUE);

addView(rightButton,rightParams);

titleParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT);

titleParams.addRule(RelativeLayout.CENTER_IN_PARENT,TRUE);

addView(tvTitle,titleParams);

leftButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

listener.leftClick();

}

});

rightButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

listener.rightClick();

}

});

}

}

xml/代碼

<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android="http://schemas.android.com/apk/res/android"

? ? ? ?xmlns:custom="http://schemas.android.com/apk/res/com.example.recipes">

<LinearLayout?

android:orientation="vertical"?

android:layout_width="fill_parent"?

android:layout_height="fill_parent">

<com.example.recipes.Topbar

? ?android:id="@+id/topbar"

? ?android:layout_width="match_parent"?

android:layout_height="45dp"

custom:leftBackground="@drawable/servise"

custom:leftTextColor="#FFFFFF"

custom:rightBackground="@drawable/saerch"

custom:rightTextColor="#FFFFFF"

? ? ? ? custom:title="分類"

? ? ? ? custom:titleTextColor="#123412"

? ? ? ? custom:titleTextSize="10sp">

? ?

</com.example.recipes.Topbar>

<LinearLayout?

android:orientation="vertical"?

android:layout_width="fill_parent"?

android:layout_height="0dp"?

android:layout_weight="1">

<ListView?

android:id="@+id/app_index_list_view"?

android:layout_width="fill_parent"?

android:layout_height="wrap_content"?

android:descendantFocusability="blocksDescendants"

android:fadingEdge="vertical"?

android:fadingEdgeLength="5dip"?

android:divider="@null"

android:cacheColorHint="#00000000" />

</LinearLayout>

<include layout="@layout/tab" />

</LinearLayout>

</merge>


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
Android UI模板設(shè)計
  • 參與學(xué)習(xí)       76030    人
  • 解答問題       233    個

快來學(xué)習(xí)如何在Android中自定義View,本次課程一定會讓你獲益匪淺

進入課程

右Button跑到左邊并且覆蓋左Button

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號