gpt4 book ai didi

Android 图片 View 和 ListView

转载 作者:行者123 更新时间:2023-11-29 17:55:10 25 4
gpt4 key购买 nike

我想做一个文件管理器之类的东西。我有一个文件列表,当我单击一个文件时,如果它是一个图像,我必须在预览中显示它。因此,我制作了一个表格布局,其中有两行:第一行是包含所有文件的 ListView ,第二行是我要显示图像的 ImageView 。问题是当我将图像添加到 ImageView 时它根本没有出现。这是布局:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom" >

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ImageView>
</TableRow>
</TableLayout>

这是我将图像添加到 ImageView 的地方(我必须这样做,因为我的文件在 sdcard 上)

ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageURI(Uri.fromFile(file));

有人能告诉我我做错了什么吗?谢谢

最佳答案

您最好使用 LinearLayout。这样效率会更高。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

</LinearLayout>

但是如果你必须使用 TableLayout(我看不出你的示例有任何理由),你可以这样使用:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TableRow
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >

<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom" >

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" >
</ImageView>
</TableRow>

</TableLayout>

关于Android 图片 View 和 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19914753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com