码迷,mamicode.com
首页 > 移动开发 > 详细

安卓顶部标题

时间:2015-10-19 21:00:30      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

package com.example.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
public class MyIndTitle extends LinearLayout {

 public MyIndTitle(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  // TODO Auto-generated constructor stub
 }

 public MyIndTitle(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
 }

 private int everyMargin=20;//??????????20.
 private int topMargin=20;//????20??
 public int allWith;
 private int allWidth;
 private int allHeight;
 public MyIndTitle(Context context, AttributeSet attrs) {
  super(context, attrs);
  // TODO Auto-generated constructor stub


 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  // TODO Auto-generated method stub
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  int childCount = getChildCount();
  allWidth = getMeasuredWidth();
  for (int i = 0; i <childCount; i++) {
   View view = getChildAt(i);
   view.measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED);
  }
  setMeasuredDimension(allWidth,allHeight);
 }
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
  // TODO Auto-generated method stub
  super.onLayout(changed, l, t, r, b);
  Log.e("para",allWidth+"");
  for (int i = 0; i <getChildCount(); i++) {
   View childView = getChildAt(i);
   if(i==0){
    topMargin=20;//???????20 ?????ж???
    childView.layout(everyMargin,topMargin,everyMargin+childView.getMeasuredWidth(),topMargin+childView.getMeasuredHeight());

   }
   else {
    View prechildView = getChildAt(i-1);
    int x=prechildView.getRight()+everyMargin;
    if(x+childView.getMeasuredWidth()+everyMargin<=allWidth){
     childView.layout(x, topMargin,x+childView.getMeasuredWidth(),topMargin+childView.getMeasuredHeight());
    }
    else {
     childView.layout(everyMargin,prechildView.getBottom()+20,everyMargin+childView.getMeasuredWidth(),prechildView.getBottom()+20+childView.getMeasuredHeight());
     topMargin=prechildView.getBottom()+20;
     allHeight=prechildView.getBottom()+20+childView.getMeasuredHeight();//????????????
    }
   }}

 }

 @Override
 protected void dispatchDraw(Canvas canvas) {
  // TODO Auto-generated method stub
  super.dispatchDraw(canvas);
 }

 

 

 

}

安卓顶部标题

标签:

原文地址:http://my.oschina.net/u/2334470/blog/519052

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!