Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法增加UrlImageView大小!(安卓)_Java_Android_Android Layout_Android Ui_Android Xml - Fatal编程技术网

Java 无法增加UrlImageView大小!(安卓)

Java 无法增加UrlImageView大小!(安卓),java,android,android-layout,android-ui,android-xml,Java,Android,Android Layout,Android Ui,Android Xml,我有一个定制的imageWiew(UrlImageView),它是一个通过JSON从YouTube上提取的缩略图。但它的表现很不寻常 我熟悉常见的罪魁祸首——没有设置android:scaleType(fillXY或centerCrop),或者可能忘记了match_parent——但是我尝试了很多组合。似乎没有什么能使应用程序中的缩略图变大 这让我想到。。。嗯-也许我从YouTube上得到了一个小小的缩略图!不。。。它正在使用和返回hqdefault: http://img.youtube.co

我有一个定制的imageWiew(UrlImageView),它是一个通过JSON从YouTube上提取的缩略图。但它的表现很不寻常

我熟悉常见的罪魁祸首——没有设置android:scaleType(fillXY或centerCrop),或者可能忘记了match_parent——但是我尝试了很多组合。似乎没有什么能使应用程序中的缩略图变大

这让我想到。。。嗯-也许我从YouTube上得到了一个小小的缩略图!不。。。它正在使用和返回hqdefault:

http://img.youtube.com/vi/jXE6G9CYcJs/hqdefault.jpg
我已经为此苦苦挣扎了一段时间,我想我需要找到一种方法,在layout framework developer选项打开的情况下,控制/修改/调整此处显示的任何布局或布局参数:

我想可能是:

A.布局宽度和布局高度参数的错误组合(可能是父母以我不知道的方式影响孩子)

B.java和XML参数之间的冲突

C.一些明显的东西(我不小心忽略了)

D.我的源代码与我用作示例的源代码之间的修改或差异,以构建我所拥有的内容(整个软件包可在此链接获得-如果有人想下载并快速确定,应该会有所帮助)

E.异常/不寻常(我在5英寸屏幕的设备上进行大多数测试-它是Star N920e[奇怪-嗯?我知道…但是开发必须在这个设备上完成。我会在模拟器中尝试任何解决方案,以避免任何曙光地带问题-但我只想澄清,到目前为止,我的大部分测试都是这样做的-这可能是一个错误。考虑到这一点-请随意提出建议,并对您最喜欢的回答进行投票-让我们看看是什么在这一个上浮动到顶部!】


附言

请原谅这篇有争议的长篇文章-我想我有家长/孩子的问题,加上教程使用了2个xml文件来实例化所有内容,所以我包括了这些内容以及我正在使用的java。我道歉-但我认为这是必要的

此外,如果您想下载示例项目-然后插入我所做的(错误)源代码,可直接在此处找到:

home.xml:
提前感谢!尝试将
android:adjustViewBounds
设置为true。您可能还想将
layout\u width
调整为
match\u parent

我这样做了……仍然没有,luckI在这个版本中还有一些其他问题……介意看看吗?
<?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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="120dp"
        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.example.project.ui.widget.VideosListView
            android:id="@+id/videosListView"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        </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="wrap_content"
                    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>
<?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="true"
        android:background="@android:color/black"
        android:scaleType="fitXY"
        android:clickable="false"
        android:contentDescription="YouTube video thumbnail"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center"
        android:src="@drawable/ic_launcher" />

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:visibility="invisible" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/userVideoTitleTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dip"
            android:text="Video Title Not Found"
            android:textColor="@android:color/black"
            android:textSize="20sp" />

        <Button
            android:id="@+id/fav_up_btn1"
            android:layout_width="27dp"
            android:layout_height="27dp"
            android:layout_alignParentRight="true"
            android:background="@drawable/fav_up_btn1"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="right"
            android:paddingRight="5dp"
            android:paddingTop="5dp" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/userVideouploaderTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dip"
            android:textColor="@color/verylightgrey"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/userVideoviewsTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/userVideouploaderTextView"
            android:textColor="@android:color/black"
            android:textSize="16sp" />
    </RelativeLayout>

</LinearLayout>
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);

        mSpinner = new ProgressBar(mContext);
        mSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        mSpinner.setIndeterminate(true);

        addView(mSpinner);
        addView(mImage);
    }


    public void setImageDrawable(final String imageUrl) {
        mDrawable = null;
        mSpinner.setVisibility(View.VISIBLE);
        mImage.setVisibility(View.GONE);

        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();
    }


    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);

                mSpinner.setVisibility(View.GONE);
                break;
            case RESULT_CANCELED:
            default:

                break;
            }
            return true;
        }
    });


    private static Drawable getDrawableFromUrl(final String url) throws IOException, MalformedURLException {
        return Drawable.createFromStream(((java.io.InputStream) new java.net.URL(url).getContent()), "name");
    }

}