除了我看不到我的ListView应用程序的最后几个视图外,其他一切似乎都还不错(除了很懒)。我试图为每个ListView项更改自定义视图布局的高度,但我意识到高度越小,看不到的视图越多。这意味着ListView的底部有固定的高度长度,我无法滚动到该高度,我也不知道为什么。
MainActivity.java中的代码
public class MainActivity extends AppCompatActivity {
String[] titles;
String[] descriptions;
int[] drawables = {R.drawable.number0, R.drawable.number2, R.drawable.number3, R.drawable.number4, R.drawable.number5, R.drawable.number6, R.drawable.number7, R.drawable.number8, R.drawable.number9, R.drawable.number10};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
titles = res.getStringArray(R.array.title);
descriptions = res.getStringArray(R.array.description);
ListView l = (ListView) findViewById(R.id.listview);
myadapter myadapter = new myadapter(this, titles, drawables, descriptions);
l.setAdapter(myadapter);
}
}
class myadapter extends ArrayAdapter<String>{
Context c;
int[] drawables;
String[] titles;
String[] descriptions;
public myadapter(Context context, String[] titles, int[] drawables, String[] descriptions ) {
super(context,R.layout.single_row, R.id.title,titles);
c=context;
this.drawables = drawables;
this.titles = titles;
this.descriptions = descriptions;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater i = (LayoutInflater) c.getSystemService(c.LAYOUT_INFLATER_SERVICE);
v = i.inflate(R.layout.single_row, parent, false);
}
ImageView image = (ImageView) v.findViewById(R.id.image);
TextView title = (TextView) v.findViewById(R.id.title);
TextView description = (TextView) v.findViewById(R.id.description);
image.setImageResource(drawables[position]);
title.setText(titles[position]);
description.setText(descriptions[position]);
return v;
}
}
来自自定义布局xml文件的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<ImageView
android:id="@+id/image"
android:layout_width="90dp"
android:layout_height="90dp"
app:srcCompat="@drawable/number0" />
<TextView
android:id="@+id/title"
android:layout_width="332dp"
android:layout_height="36dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="@+id/image"
android:layout_toRightOf="@+id/image" />
<TextView
android:id="@+id/description"
android:layout_width="320dp"
android:layout_height="49dp"
android:layout_below="@+id/title"
android:layout_alignStart="@id/title"
android:layout_alignLeft="@id/title"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="@+id/image"
android:layout_toRightOf="@+id/image" />
</RelativeLayout>
activity_main.xml文件仅包含一个列表视图。
答案 0 :(得分:1)
视频教程使用png文件格式,他可能使用的是更小的文件。您的列表视图可能很慢,因为要花很多时间才能显示很多资源?您尝试只显示文字吗?
对不起,这更像是评论而不是答案,但是直到达到50次代表我才能发表评论