
布局本身很好用,但我不能让这个布局中的按钮上的文本居中.
当我在linearLayout中放置相同的按钮时,按钮文本按照需要居中,因此故障可能在我的布局中.
但是我的布局如何影响其子视图上文本的严重性?我怀疑它与布局参数有关,但我真的不知道它是如何工作的.
以下是一些可能与问题相关的代码段:
我的布局类WeightedGrIDLayout:
public class WeightedGrIDLayout extends VIEwGroup {// ...@OverrIDeprotected voID onLayout(boolean changed,int left,int top,int right,int bottom) { for (int i = 0,N = getChildCount(); i < N; i++) { VIEw c = getChildAt(i); // ... // do some calculation // c.layout( childleft,childtop,childRight,childBottom ); } }public static class LayoutParams extends VIEwGroup.marginLayoutParams { public position position = position( 0,0 ); public Span span = span( 1,1 ); // position and Span are local classes which are irrelevant herepublic LayoutParams( position position,Span span ) { super(FILL_PARENT,FILL_PARENT); this.position = position; this.span = span;}public LayoutParams( position position ) { this( position,span(1,1) );}public LayoutParams() { this( position(0,0),1) );}public LayoutParams(marginLayoutParams params) { super(params);}public LayoutParams(LayoutParams that) { super(that); this.position = that.position; this.span = that.span;}public LayoutParams(Context context,AttributeSet attrs) { super(context,attrs);}} 该类使用如下:
WeightedGrIDLayout grID = (WeightedGrIDLayout) findVIEwByID(R.ID.mainMenu); LayoutInflater inflater = getLayoutInflater(); button button = (button)inflater.inflate(R.layout.buttonpropertIEs,null); button.setText( "None" ); WeightedGrIDLayout.position pos = WeightedGrIDLayout.position(colIDx,rowIDx); WeightedGrIDLayout.LayoutParams lp = new WeightedGrIDLayout.LayoutParams(pos); lp.setmargins(5,20,5,20); grID.addVIEw(button,lp );
以下是按钮的属性:
<button xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:background="@drawable/default_button" androID:gravity="center" androID:textSize="@dimen/text" androID:textcolor="@color/text" ></button>
按钮文本显示在按钮顶部而不是中心.
为了将文本传到中心,我该怎么办?
以上是内存溢出为你收集整理的Android自定义布局重力全部内容,希望文章能够帮你解决Android自定义布局重力所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)