android - gridview 的样式自定义适配器

标签 android android-layout

我想得到什么::
<我正在尝试在横向和纵向模式下显示相同的外观>

enter image description here


我现在有什么:: <观察 imageview 在不同方向模式下的外观不同> imageview 的高度在纵向模式下更多

enter image description here enter image description here


grid_single.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#222222"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#E6E6E6"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/grid_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:src="@drawable/eleven" >
                </ImageView>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#FFFFFF"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/grid_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:text="Text"
                    android:textSize="12sp" >
                </TextView>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <GridView
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:listSelector="#00000000"
        android:numColumns="auto_fit" />

</LinearLayout>

最佳答案

尝试将您的 ImageView xml 更改为:

<ImageView
    android:id="@+id/grid_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:scaleType="fitXY"
    android:src="@drawable/eleven" >
</ImageView>

您有一个很好的不同 android:scaleType 显示示例,以及它们的行为方式 here .

关于android - gridview 的样式自定义适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25046172/

相关文章:

android - Google Play 游戏 - alpha/beta 测试中的应用程序 - 登录时出现错误 10004 结果应用程序配置错误

Android检查之前是否购买了应用内购买

java - 即使在对话框显示并关闭后,如何保持底部控制栏始终隐藏?

java - 将适配器应用于 Spinner 会导致 NullPointerException?

java - Android - 从同类访问 Servlet AsyncPost 任务响应

安卓 : How to simply add categories/Separators/Section header in my list view?

android - 我如何设计一个移动应用程序来跟踪其他应用程序

android - Android 6 上的 SurfaceView 旋转问题

android - 如何将 WebView 的背景颜色设置为十六进制值?

android - 使用默认身份验证在 FB 上发布照片并获取照片已发布的消息的简单技术