多个列表视图正在削减 [英] multiple listview are being cut
问题描述
有一个问题,当我试图让多个列表视图一个LinearLayout中的IM。最初当我加入含有一个TextView和一个ListView我不能向下滚动页面的多个自定义linearlayouts所以我发现添加滚动视图会解决这个问题,它没有,但由于某种原因,然后冒出了的LinearLayout视图,所以我只能看到每个列表的顶部。
im having an issue when i try to make a linearlayout with multiple listviews. originally when i added multiple custom linearlayouts containing a textview and a listview i could not scroll down the page so i found out adding a scrollview would fix this, which it did but for some reason it then cropped the linearlayout view so i could only see the top part of each list.
继承人的code的不同部分:
heres the code for the different parts:
主要布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/whatsNewTitle"
android:text="Whats New?"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="30dip">
</TextView>
<Button android:layout_height="wrap_content"
android:id="@+id/home"
android:text="Home"
android:layout_weight="0.07"
android:layout_width="126dp">
</Button>
<ScrollView
android:id="@+id/sv1"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_height="630dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="@+id/whats_new_content"
android:layout_height="fill_parent">
</LinearLayout>
</ScrollView>
</LinearLayout>
布局IM膨胀和增加多次到主要布局:
layout im inflating and adding multiple times into main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/new_date"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:textSize="25dip">
</TextView>
<ListView
android:id="@+id/new_files"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#000000">
</ListView>
</LinearLayout>
这是创建多个列表视图,并显示他们的主要活动:
the main activity that creates the multiple listviews and displays them:
public class WhatsNew extends Activity{
private Button homeBtn;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.whats_new_main);
CreateLastModDateList();
homeBtn = (Button) findViewById(R.id.home);
homeBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v){
Intent myIntent = new Intent(getApplication().getApplicationContext(),
Main.class);
startActivityForResult(myIntent, 0);
}
});
}
private ArrayList<File> GenerateNewFileDates(){
Files.clearFilesList();
Files.buildFilesList(Files.getRoot());
return Files.getAllFiles();
}
private void CreateLastModDateList(){
ArrayList<File> files = GenerateNewFileDates();
ArrayList<String> allDates = new ArrayList<String>();
ArrayList<String> dates = new ArrayList<String>();
Context c = this.getApplicationContext();
LinearLayout l = (LinearLayout) findViewById(R.id.whats_new_content);
/** Builds a list of all file dates **/
for(File file : files){
Date lastModifiedDate = new Date(file.lastModified());
allDates.add(lastModifiedDate.toString());
}
/** For each date, check if we have already put that date into the dates array
if we have then we want to ignore it, otherwise add it to the dates array. **/
for(String date : allDates){
if (exists(dates,date) == false){
dates.add(date);
}
}
for(String date : dates){
ArrayList<String> test = new ArrayList<String>();
test = generateFileList(date, files);
WhatsNewLayout whatsNew = new WhatsNewLayout(c,test, date);
l.addView(whatsNew);
}
}
public ArrayList<String> generateFileList(String date, ArrayList<File> mFiles){
ArrayList<String> filesFromDate = new ArrayList<String>();
for(File file : mFiles){
Date lastModifiedDate = new Date(file.lastModified());
boolean x = lastModifiedDate.toString().equals(date);
if (x == true){
filesFromDate.add(file.getName());
}
}
return filesFromDate;
}
public boolean exists(ArrayList<String> list, String compare){
boolean result = false;
if(list.contains(compare)){
result = true;
}
return result;
}
}
我的LinearLayout定制的膨胀:
The custom linearlayout i inflate:
public class WhatsNewLayout extends LinearLayout {
private LayoutInflater mInflater;
public WhatsNewLayout(Context context, ArrayList<String> files, String date) {
super(context);
mInflater = LayoutInflater.from(context);
View convertView = new View(context);
/** initialize variables **/
DataHolder holder;
Context c = this.getContext();
ArrayAdapter<String> list = new ArrayAdapter<String>(c,
android.R.layout.simple_list_item_1, files);
convertView = mInflater.inflate(R.layout.whats_new_item, null);
holder = new DataHolder();
holder.modDate = (TextView) convertView.findViewById(R.id.new_date);
holder.FileList = (ListView) convertView.findViewById(R.id.new_files);
convertView.setTag(holder);
holder.modDate.setText(date);
holder.FileList.setAdapter(list);
this.addView(convertView);
}
}
很抱歉的大型群众code,但我不想留下任何细节了的情况下,这是非常重要的,希望这就是一切,我敢肯定它的东西真的fundermental我布局的电话,但我只是不能看到什么是casuing自定义布局将会被削减。
Sorry about the large mass of code, but i didnt want to leave any details out in case it is important, hopefully this is everything, im sure its something really fundermental with my call of the layout but i just cannot see what is casuing the custom layout to be cut.
如果需要进行任何详细信息,请让我知道。 =)
if any more details are required please let me know. =)
推荐答案
把你的列表视图中垂直滚动。您可以通过下面的技巧有一个垂直滚动内滚动的ListView。请使用以下code和享受!
Put your listViews in a vertical scroll. You can have scrollable listView inside of a vertical scroll by the following trick. use the following code and enjoy!
private int listViewTouchAction;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
setListViewScrollable(myListView1);
setListViewScrollable(myListView2);
}
private void setListViewScrollable(final ListView list) {
list.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
listViewTouchAction = event.getAction();
if (listViewTouchAction == MotionEvent.ACTION_MOVE)
{
list.scrollBy(0, 1);
}
return false;
}
});
list.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view,
int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (listViewTouchAction == MotionEvent.ACTION_MOVE)
{
list.scrollBy(0, -1);
}
}
});
}
listViewTouchAction是一个全球性的整数值。
listViewTouchAction is a global integer value.
这篇关于多个列表视图正在削减的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!