Android 将服务器映像填充到NetworkImageview,而不拉伸它
我拥有的 我从服务器上获得了Android 将服务器映像填充到NetworkImageview,而不拉伸它,android,layout,imageview,android-volley,Android,Layout,Imageview,Android Volley,我拥有的 我从服务器上获得了ImageUri,我正在将其设置为我的NetworkImageview凌空库 我想要什么 我希望图像占据网络图像视图的全宽和高(与facebook类似) 我的问题 我看到我的网络图像视图的宽度为白色彩色左侧 我的代码 xml布局 <RelativeLayout android:id="@+id/relative_profile_hotot" android:layout_width="match_parent" a
ImageUri
,我正在将其设置为我的NetworkImageview
凌空库
我想要什么
我希望图像占据网络图像视图的全宽
和高
(与facebook类似)
我的问题
我看到我的网络图像视图的宽度
为白色彩色
左侧
我的代码
xml布局
<RelativeLayout
android:id="@+id/relative_profile_hotot"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="@+id/relative_profile_header"
android:padding="0dp">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/img_post_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="center"
android:src="@drawable/image_palce" />
<RelativeLayout
android:id="@+id/relative_profile_footer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@color/profile_footer_bg">
<TextView
android:id="@+id/tv_profile_photo_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:drawableLeft="@drawable/ic_home_place"
android:drawablePadding="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/grey_dark"
android:textSize="@dimen/txt_small"
tools:text="Paris France" />
<TextView
android:id="@+id/tv_profile_photo_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tv_profile_photo_location"
android:layout_marginLeft="20dp"
android:ems="40"
android:padding="2dp"
android:singleLine="true"
android:textColor="@color/grey_light"
android:textSize="@dimen/txt_very_small"
tools:text="Effel Tower,...Read more" />
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_foot"
android:src="@drawable/ic_home_footstep_color"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/tv_profile_comment" />
<TextView
android:id="@+id/tv_profile_foot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="@color/grey_light"
android:textSize="@dimen/txt_small"
tools:text="150"
android:layout_alignBottom="@+id/tv_profile_photo_description"
android:layout_alignEnd="@+id/tv_profile_photo_description" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_cheers"
android:src="@drawable/ic_home_cheers_color"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/img_comment"
android:layout_marginEnd="14dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_comment"
android:src="@drawable/ic_home_coments"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/tv_profile_comment" />
<TextView
android:id="@+id/tv_profile_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="@color/grey_light"
android:textSize="@dimen/txt_small"
tools:text="264"
android:layout_alignBottom="@+id/tv_profile_photo_description"
android:layout_toStartOf="@+id/tv_profile_foot" />
<TextView
android:id="@+id/tv_profile_cheers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="@color/grey_light"
android:textSize="@dimen/txt_small"
tools:text="3164"
android:layout_alignBottom="@+id/tv_profile_photo_description"
android:layout_toStartOf="@+id/img_comment" />
</RelativeLayout>
</RelativeLayout>
屏幕截图:(
更换
android:scaleType="center"
与
在您的NetworkImageView中我使用NetworkImageView时也遇到了同样的情况。问题是,它的行为与ImageView稍有不同,并且当屏幕的密度大于要插入的图像的宽度时,android:scaleType=“centerCrop”
不足以填充宽度。
请尝试此代码,在运行时更改图像的宽度,并将其调整为屏幕的密度
在layout.xml中
<com.android.volley.toolbox.NetworkImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:id="@+id/imagePagerView"/>
您没有清楚地发布您的问题。请重新表述您的问题,这没有多大意义。如果我使用centerCrop,我的完整图像将不可见。您希望方形图像在不修改纵横比的情况下适合矩形?或者图像拉伸可以吗?(这与facebook不同)图像不应该拉伸。如果你提到这个问题,我会立即回答。在我看来,这是最干净的解决方案:只需从NetworkImageView而不是ImageView扩展它
android:scaleType="centerCrop"
<com.android.volley.toolbox.NetworkImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:id="@+id/imagePagerView"/>
Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
float scWidth = outMetrics.widthPixels;
float scHeigh = outMetrics.heightPixels;
mImageView.getLayoutParams().width = (int) scWidth;
mImageView.getLayoutParams().height = (int) scHeigh;