gpt4 book ai didi

java - 异常的 Android UI 问题 : android:scaleType="fitXY and match_parent will not increase the size of an ImageView -

转载 作者:太空宇宙 更新时间:2023-11-04 15:17:32 24 4
gpt4 key购买 nike

我有一个缩略图,其行为非常奇怪。我已将其参数设置为 match_parent 以及 android:scaleType="fitXY" 并且似乎都对缩略图没有任何影响(所需的行为是填充到屏幕边缘)。

XML:list_item_user_video.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<com.example.project.ui.widget.UrlImageView
android:id="@+id/userVideoThumbImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="false"
android:clickable="false"
android:contentDescription="YouTube video thumbnail"
android:focusable="false"
android:scaleType="fitXY"
android:focusableInTouchMode="false"
android:gravity="center"
android:src="@drawable/ic_launcher" />

Home.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:id="@+id/content_frame"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>

<ListView
android:id="@+id/left_drawer"
android:layout_width="220dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/darkgrey"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:textStyle="bold" />

<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AAFFFFFF" >

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

<com.idg.omv.ui.widget.VideosListView
android:id="@+id/videosListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >

<RelativeLayout
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true" >

<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@color/darkgrey"
android:scaleType="centerCrop"
android:src="@drawable/home_up_btn" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true" >

<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ImageButton
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:focusable="false"
android:src="@drawable/scroll_lt_arrow" />

<ImageButton
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:focusable="false"
android:src="@drawable/scroll_rt_arrow" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

</android.support.v4.widget.DrawerLayout>

JAVA:

public class UrlImageView extends LinearLayout {

private Context mContext;
private Drawable mDrawable;
private ProgressBar mSpinner;
private ImageView mImage;

public UrlImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}

public UrlImageView(Context context) {
super(context);
init(context);
}

/**
* First time loading of the LoaderImageView
* Sets up the LayoutParams of the view, you can change these to
* get the required effects you want
*/
private void init(final Context context) {
mContext = context;

mImage = new ImageView(mContext);
mImage.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mImage.setVisibility(View.GONE);
mImage.setScaleType(ScaleType.FIT_XY);
mSpinner = new ProgressBar(mContext);
mSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

mSpinner.setIndeterminate(true);

addView(mSpinner);
addView(mImage);
}

/**
* Set's the view's drawable, this uses the internet to retrieve the image
* don't forget to add the correct permissions to your manifest
*
* @param imageUrl the url of the image you wish to load
*/
public void setImageDrawable(final String imageUrl) {
mDrawable = null;
mSpinner.setVisibility(View.VISIBLE);
mImage.setVisibility(View.GONE);
mImage.setScaleType(ScaleType.FIT_XY);
new Thread() {
public void run() {
try {
mDrawable = getDrawableFromUrl(imageUrl);
imageLoadedHandler.sendEmptyMessage(RESULT_OK);
} catch (MalformedURLException e) {
imageLoadedHandler.sendEmptyMessage(RESULT_CANCELED);
} catch (IOException e) {
imageLoadedHandler.sendEmptyMessage(RESULT_CANCELED);
}
};
}.start();
}

/**
* Callback that is received once the image has been downloaded
*/
private final Handler imageLoadedHandler = new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case RESULT_OK:
mImage.setImageDrawable(mDrawable);
mImage.setVisibility(View.VISIBLE);
mImage.setScaleType(ScaleType.FIT_XY);
mSpinner.setVisibility(View.GONE);
break;
case RESULT_CANCELED:
default:
// Could change image here to a 'failed' image
// otherwise will just keep on spinning
break;
}
return true;
}
});

/**
* Pass in an image url to get a drawable object
*
* @return a drawable object
* @throws IOException
* @throws MalformedURLException
*/
private static Drawable getDrawableFromUrl(final String url) throws IOException, MalformedURLException {
return Drawable.createFromStream(((java.io.InputStream) new java.net.URL(url).getContent()), "name");
}

}

最佳答案

您是否尝试过使用 WRAP_CONTENT 而不是 MATCH_PARENT?为什么要将图像一直拉伸(stretch)到边缘?这看起来会很糟糕。

关于java - 异常的 Android UI 问题 : android:scaleType="fitXY and match_parent will not increase the size of an ImageView -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20746893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com