我目前在列表行布局中有一个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>
如何为每个项目保持两侧的填充相同?
答案 0 :(得分: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"
/>