如何滚动布局其中有3个列表视图 [英] How to scroll layout which have 3 list view
问题描述
我有一个布局。这种布局包含3列表视图WRAP_CONTENT数据在ListView没有固定的高度。当列表视图有liitel庞大的数据当时的数据去下面,数据不能看到,所以我要滚动视图与所有三个列表视图这是如何可能的。
I have one layout. This layout contain 3 list view with the height of wrap_content data in the Listview are not fix. When Listview have a liitel huge data at that time the data goes to underneath and the data can not able to see,so i want to scroll the view with all three Listview how it is possible.
任何一个有这个想法?
这是我的看法包含3列表视图,现在是用更少的数据,但是当数据将大量当时的最后一个列表视图有问题可以查看。我要滚动的灰色视图...
This is my view which contain 3 Listview, now it's with the less data but when the data will make huge at that time the last Listview have a problem to view. I want to scroll the grey colored view...
推荐答案
使用线性布局,而不是列表视图中的XML文件。 这是你的XML文件。
Use linear layout instead of listview in your xml file. This is your xml file.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/scr" android:layout_height="fill_parent"
android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/r2" android:orientation="vertical"
android:layout_height="fill_parent" android:paddingTop="100dip"
android:paddingBottom="100dip">
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/l1" android:orientation="vertical"
android:layout_height="wrap_content" android:layout_marginTop="10dip"
android:background="#00B2EE">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/l2" android:orientation="vertical"
android:layout_height="wrap_content" android:layout_marginTop="10dip"
android:background="#00EE76">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/l3" android:orientation="vertical"
android:layout_height="wrap_content" android:layout_marginTop="10dip"
android:background="#7171C6">
</LinearLayout>
</LinearLayout>
</ScrollView>
和把另一个XML将由列表中膨胀。
and put another xml which will be inflated by list.
这是你的主要活动类。
package com.list.add;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class NewlistActivity extends Activity {
/** Called when the activity is first created. */
LinearLayout l1,l2,l3;
ScrollView scrollView;
ViewGroup contentView;
List<String> list = new ArrayList<String>();
List<String> list1 = new ArrayList<String>();
List<String> list2 = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
l1 = (LinearLayout) findViewById(R.id.l1);
l2 = (LinearLayout) findViewById(R.id.l2);
l3 = (LinearLayout) findViewById(R.id.l3);
scrollView = (ScrollView) findViewById(R.id.scr);
contentView = (ViewGroup) findViewById(R.id.r2);
scrollView.setOnTouchListener(new ScrollPager(scrollView, contentView));
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, contentView.getPaddingTop());
}
});
list.add("Parth");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Parth");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Shah");
list.add("Parth");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Parth");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Chirag");
list.add("Shah");
list1.add("Parth");
list1.add("Parth");
list1.add("Parth");
list1.add("Parth");
list1.add("Parth");
list1.add("Parth");
list2.add("Kalpesh");
list2.add("Kalpesh");
list2.add("Kalpesh");
list2.add("Kalpesh");
list2.add("Kalpesh");
list2.add("Kalpesh");
list2.add("Kalpesh");
System.out.println(list);
System.out.println(list1);
System.out.println(list2);
for (int i=0; i<list.size(); i++)
{
LayoutInflater inflater = getLayoutInflater();
View vi = inflater.inflate(R.layout.raw, null);
TextView tv = (TextView) vi.findViewById(R.id.textView1);
tv.setText(list.get(i));
l1.addView(vi);
}
for (int i=0; i<list1.size(); i++)
{
LayoutInflater inflater = getLayoutInflater();
View vi = inflater.inflate(R.layout.raw, null);
TextView tv = (TextView) vi.findViewById(R.id.textView1);
tv.setText(list1.get(i));
l2.addView(vi);
}
for (int i=0; i<list2.size(); i++)
{
LayoutInflater inflater = getLayoutInflater();
View vi = inflater.inflate(R.layout.raw, null);
TextView tv = (TextView) vi.findViewById(R.id.textView1);
tv.setText(list2.get(i));
l3.addView(vi);
}
}
}
和做出像这样的卷轴类:
and make one scroller class like this:
public class ScrollPager implements OnTouchListener
public ScrollPager(ScrollView aScrollView, ViewGroup aContentView)
{
mScrollView = aScrollView;
mContentView = aContentView;
scroller = new Scroller(mScrollView.getContext(), new OvershootInterpolator());
task = new Runnable()
{
public void run()
{
scroller.computeScrollOffset();
mScrollView.scrollTo(0, scroller.getCurrY());
if (!scroller.isFinished())
{
mScrollView.post(this);
}
}
};
}
public boolean onTouch(View v, MotionEvent event)
{
// Stop scrolling calculation.
scroller.forceFinished(true);
// Stop scrolling animation.
mScrollView.removeCallbacks(task);
if (event.getAction() == MotionEvent.ACTION_UP)
{
这篇关于如何滚动布局其中有3个列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!