主要问题就像标题说的,基于ViewGroup的滑动界面动态添加的数据为什么不显示?
我现在有一个从ViewGroup继承下来的滑动界面ScorllLayout,可左右滑动,在程序初始化时添加了三个子ViewLayoutInflater factory = LayoutInflater.from(this);
for (int i = 0; i < 3; i++)
{
m_childView[i] = factory.inflate(R.layout.childview, null);
m_ScrollLayout.addView(m_childView[i]);
}
这个childview是这样的,注意,里边用了ViewStub<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<ViewStub android:id="@+id/childview_viewstub" android:inflatedId="@+id/panel_viewstub" android:layout="@layout/childview_item"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
childview_item.xml是很简单的,如下:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/textView1" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffff"></TextView>
<EditText android:layout_width="wrap_content" android:text="EditText" android:layout_height="wrap_content" android:id="@+id/editText1"
android:background="#ff0000"></EditText>
</LinearLayout>
程序可以在三屏之间来回滑动,考虑到效率和内存,布局里边我用上ViewStub,当然,贴上来的只是一个精简后的DEMO,我想在滑动到哪屏时将哪屏的ViewStub通过inflate()显示出来,但是现在不知道怎么回来显示不出来,除非我在滑动界面所在的Activity的onCreate函数中事先将每个屏的ViewStub inflate()出来,否则就是界面可滑动,但上边什么都没有,如果事先inflate出来,那么就达不到提高效率和减少内存的目的了,这个问题困扰我好几天了,麻烦大家一起看下程序代码是没有逻辑问题的,如果不用ViewStub,那界面上是完全正常的,所以ScorllLayout类是没有问题的
我现在有一个从ViewGroup继承下来的滑动界面ScorllLayout,可左右滑动,在程序初始化时添加了三个子ViewLayoutInflater factory = LayoutInflater.from(this);
for (int i = 0; i < 3; i++)
{
m_childView[i] = factory.inflate(R.layout.childview, null);
m_ScrollLayout.addView(m_childView[i]);
}
这个childview是这样的,注意,里边用了ViewStub<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<ViewStub android:id="@+id/childview_viewstub" android:inflatedId="@+id/panel_viewstub" android:layout="@layout/childview_item"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
childview_item.xml是很简单的,如下:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/textView1" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffff"></TextView>
<EditText android:layout_width="wrap_content" android:text="EditText" android:layout_height="wrap_content" android:id="@+id/editText1"
android:background="#ff0000"></EditText>
</LinearLayout>
程序可以在三屏之间来回滑动,考虑到效率和内存,布局里边我用上ViewStub,当然,贴上来的只是一个精简后的DEMO,我想在滑动到哪屏时将哪屏的ViewStub通过inflate()显示出来,但是现在不知道怎么回来显示不出来,除非我在滑动界面所在的Activity的onCreate函数中事先将每个屏的ViewStub inflate()出来,否则就是界面可滑动,但上边什么都没有,如果事先inflate出来,那么就达不到提高效率和减少内存的目的了,这个问题困扰我好几天了,麻烦大家一起看下程序代码是没有逻辑问题的,如果不用ViewStub,那界面上是完全正常的,所以ScorllLayout类是没有问题的
解决方案 »
- 开发音乐播放器如何实现播放列表
- 5分钟实现Android手机上的指南针应用
- android 在service中用onStart()获取activity传递的值,能接受到这个值,但是不能应用于全局变量呢?
- android socket 长连接的问题
- 问一个关于Android新浪客户端的问题。
- android读取gml并且显示
- android中如何根据已知的多点画出弧度曲线
- TabActivity跳转同一Avtivity不刷新
- testActivity不能相应LifecycleOwner
- 只有.key文件,注意不是keystore文件,如何查看它的sha256等信息。
- 【【【】】】SD卡路劲求助【【【】】】
- 跪求高手解决、struts2传送json的问题、、
可以参考下这里http://webservices.ctocio.com.cn/453/12150453.shtml
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int childCount = getChildCount();
for(int i = 0; i < childCount; i++){
View v = getChildAt(i);
v.measure(widthMeasureSpec, heightMeasureSpec);
}
} @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childCount = getChildCount();
for(int i = 0; i < childCount; i++){
View v = getChildAt(i);
v.layout(l, t, r, b);
}
}参考:http://www.189works.com/article-53470-1.html