【问题标题】:ImageView doesn't show with enough padding?ImageView 没有显示足够的填充?
【发布时间】:2015-03-20 17:34:47
【问题描述】:

我目前在列表行布局中有一个 ImageView,当图像的源高于它的宽度时,它可以正确显示,但由于某种原因,当它的宽度大于它的高度时,图像显示太宽。这是一个示例,其中顶部图像太宽(正如我在图像中的蓝色文本中指出的那样),而下面的图像应该是这样的:

顶部图像这样做只是因为 ImageView 显示的位图比它高,对于任何比它高的位图它都像底部一样正确显示。这是列表行项的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    style="@style/block"
    android:gravity="center"
    android:layout_gravity="center"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/document_list_height"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="3dp"
        android:background="@color/lightgray"
        >

        <!-- shadow -->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/shadow2"
            android:scaleType="fitXY"
            />

        <ImageView
            android:id="@+id/documentImageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:paddingLeft="5dp"
            android:paddingTop="6dp"
            android:paddingRight="4dp"
            android:layout_marginBottom="4dp"
            />

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="4dp"
            android:layout_marginBottom="4dp"
            android:background="@color/alphared"
            android:layout_alignParentBottom="true"
            >

            <!-- put in LinearLayout to use weights to define textview width as 75% of match_parent -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="4"
                android:gravity="right">

                <appuccino.simplyscan.Extra.CustomTextView
                    android:id="@+id/documentName"
                    android:layout_width="0dp"
                    android:layout_weight="3"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:textColor="@color/white"
                    app:typeface="light"
                    android:layout_marginRight="16dp"
                    android:paddingTop="8dp"
                    android:paddingBottom="4dp"
                    android:singleLine="true"
                    android:text="New Document"
                    android:textSize="27sp"/>

            </LinearLayout>

            <appuccino.simplyscan.Extra.CustomTextView
                android:id="@+id/documentPageCount"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:textColor="@color/white"
                app:typeface="italic"
                android:layout_marginRight="18dp"
                android:layout_marginBottom="16dp"
                android:text="1 page"
                android:textSize="20sp"/>

        </LinearLayout>

        <com.melnykov.fab.FloatingActionButton
            android:id="@+id/listItemFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="24dp"
            android:layout_marginBottom="@dimen/list_item_fab_bottom_margin"
            android:src="@drawable/ic_action_share"
            app:fab_colorNormal="@color/fab_red"
            app:fab_colorPressed="@color/darkred"
            app:fab_colorRipple="@color/white"
            app:fab_type="normal"
            android:visibility="visible"/>

    </RelativeLayout>


</RelativeLayout>

我怎样才能让每个项目的两边的填充相同?

【问题讨论】:

  • 离题:根据材料设计规范,每个活动应该只有一个浮动操作按钮。

标签: android listview view imageview padding


【解决方案1】:

android:cropToPadding="true" 添加到您的 ImageView 中,然后它将尊重您的填充。

        <ImageView
            android:id="@+id/documentImageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:paddingLeft="5dp"
            android:paddingTop="6dp"
            android:paddingRight="4dp"
            android:layout_marginBottom="4dp"
            android:cropToPadding="true"
            />

【讨论】:

    猜你喜欢
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    相关资源
    最近更新 更多