package com.qin.scrollerview;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
//自定义ViewGroup , 包含了三个LinearLayout控件,存放在不同的布局位置,通过scrollBy或者scrollTo方法切换
public class MultiViewGroup extends ViewGroup {
private Context mContext;
private static String TAG = "MultiViewGroup";
public MultiViewGroup(Context context) {
super(context);
mContext = context;
init();
}
public MultiViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
Log.i(TAG, "MultiViewGroup :getWidth()=" + getWidth()+","+"getHeight()="+getHeight());
mContext = context;
init();
}
private void init() {
// 初始化3个 LinearLayout控件
LinearLayout oneLL = new LinearLayout(mContext);
oneLL.setBackgroundColor(Color.RED);
addView(oneLL);
LinearLayout twoLL = new LinearLayout(mContext);
twoLL.setBackgroundColor(Color.YELLOW);
addView(twoLL);
LinearLayout threeLL = new LinearLayout(mContext);
threeLL.setBackgroundColor(Color.BLUE);
addView(threeLL);
}
// measure过程
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.i(TAG, "--- start onMeasure --");
// 设置该ViewGroup的大小
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
int childCount = getChildCount();
Log.i(TAG, "--- onMeasure childCount is -->" + childCount);
Log.i(TAG, "width=" + width+","+"height="+height);
Log.i(TAG, "onMeasure :getWidth()=" + getWidth()+","+"getHeight()="+getHeight());
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
// 设置每个子视图的大小 , 即全屏
child.measure(MultiScreenActivity.screenWidth, MultiScreenActivity.scrrenHeight);
}
}
// layout过程
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
Log.i(TAG, "--- start onLayout --");
int startLeft = 0; // 每个子视图的起始布局坐标
int startTop = 10; // 间距设置为10px 相当于 android:marginTop= "10px"
int childCount = getChildCount();
Log.i(TAG, "--- onLayout childCount is -->" + childCount);
Log.i(TAG, "onLayout :getWidth()=" + getWidth()+","+"getHeight()="+getHeight());
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
child.layout(startLeft, startTop,
startLeft + MultiScreenActivity.screenWidth,
startTop + MultiScreenActivity.scrrenHeight);
startLeft = startLeft + MultiScreenActivity.screenWidth ; //校准每个子View的起始布局位置
//三个子视图的在屏幕中的分布如下 [0 , 320] / [320,640] / [640,960]
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
实验scrollTo、scrollBy、getScrollX、getScrollY这4个方法的含义
共27个文件
class:8个
png:6个
xml:3个
5星 · 超过95%的资源 需积分: 35 442 下载量 137 浏览量
2013-03-10
01:12:56
上传
评论 1
收藏 55KB RAR 举报
温馨提示
关于自定义视图继承ViewGroup,主要是说明scrollTo、scrollBy、getScrollX、getScrollY这4个方法的含义
资源推荐
资源详情
资源评论
收起资源包目录
ViewGroup.rar (27个子文件)
ViewGroup
bin
D_ScrollerView.apk 16KB
classes.dex 7KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 2KB
classes
com
qin
scrollerview
MultiViewGroup.class 3KB
MultiScreenActivity.class 3KB
R$layout.class 405B
R$id.class 475B
R$drawable.class 406B
R$attr.class 346B
R.class 545B
R$string.class 433B
resources.ap_ 11KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
values
strings.xml 174B
drawable-mdpi
icon.png 3KB
layout
multiview.xml 951B
default.properties.bak 364B
assets
gen
com
qin
scrollerview
R.java 871B
src
com
qin
scrollerview
MultiViewGroup.java 3KB
MultiScreenActivity.java 3KB
.project 850B
.classpath 288B
project.properties 361B
AndroidManifest.xml 651B
共 27 条
- 1
yydsit.com
- 粉丝: 17
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页