的Android ImageView的填充屏幕宽度
这里我的布局文件:的Android ImageView的填充屏幕宽度
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#000"
tools:context=".CproductDetails" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_bg"
>
<ImageView
android:id="@+id/product_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_tweet_placeholder_photo_dark_error"
android:scaleType="center" />
<TextView
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textColor="#95ab56"
android:textSize="20sp"
android:layout_marginTop="7dip" />
<TextView
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="20sp"
android:textColor="#efeeea" />
<TextView
android:id="@+id/product_commerce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="20sp" />
<TextView
android:id="@+id/product_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="15sp"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip" />
<TextView
android:id="@+id/product_township"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="15sp"
android:visibility="gone"
android:layout_marginBottom="10dip"
android:drawableLeft="@drawable/location_place"
android:drawablePadding="7dip" />
<TextView
android:id="@+id/product_website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:autoLink="web"
android:textSize="15sp"
android:drawableLeft="@drawable/location_web_site"
android:drawablePadding="7dip"
android:visibility="gone" />
<TextView
android:id="@+id/product_tel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="20sp"
android:drawableLeft="@drawable/device_access_call"
android:drawablePadding="7dip"
android:visibility="gone" />
</LinearLayout>
在手机中的结果:
,结果在7英寸平板电脑:
我想使图像在平板电脑中也能满足屏幕宽度。像Twitter的应用程序,例如:
谢谢大家,但你的答案都不能解决我的问题。最后我用了Maurycy Wojtowicz的ScaleImageView课。
此视图将自动确定的宽度或高度,通过确定如果高度或宽度被设置,并且根据图像标注
网站关闭了,请更新 – fersarr 2014-03-12 06:23:26
@fersarr完成! – tsil 2014-03-13 10:40:10
该类手动将centerInside或centerCrop缩放添加到图像。对于这个问题和这个问题的10个重复部分,这是一个臃肿的版本,不需要无关的类。 – LoungeKatt 2017-04-15 16:34:51
使用android:scaleType="fitXY"
。
这将独立地缩放X和Y中的图像,以便src完全匹配dst。这 可能会更改src的宽高比。
这对于大多数照片来说都没什么用处,因为长宽比很关键 – lilbyrdie 2015-08-03 18:28:49
听起来像你想在你的ImageView上使用android:scaleType="fitCenter"
和android:adjustViewBounds="true"
。
机器人缩放其他尺寸:scaleType =“fitXY”。去为它
fitXY将采用完整的x轴和y轴作为我们描述的布局高度 – 2016-06-16 18:17:26
你的答案将取决于你的布局,所以你为什么不发布整个XML布局文件? – MarsAtomic 2013-05-05 01:26:43
android:layout_height =“fill_parent” – Raghunandan 2013-05-05 01:30:59
@MarsAtomic done – tsil 2013-05-05 01:32:55