【发布时间】:2013-12-19 17:03:18
【问题描述】:
我在 listView 中有一个 YoutubeThumbnail/ImageView,我想填充/拉伸到屏幕边缘:
<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>
和
<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" />
目前它似乎没有这样做,并且在某些设备上,缩略图看起来很小。
HTC 蝴蝶截图:
Galaxy S2 截图:
我不确定我到底做错了什么 - 感谢任何输入。
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: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>
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="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>
JAVA:
private VideosListView listView;
listView = (VideosListView) findViewById(R.id.videosListView);
listView.setOnVideoClickListener(this);
private void populateListWithVideos(Message msg) {
Library lib = (Library) msg.getData().get(
GetYouTubeUserVideosTask.LIBRARY);
listView.setVideos(lib.getVideos());
}
编辑:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.idg.omv.ui.widget.UrlImageView
android:id="@+id/userVideoThumbImageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="false"
android:background="@android:color/black"
android:clickable="false"
android:contentDescription="YouTube video thumbnail"
android:focusable="false"
android:focusableInTouchMode="false"
android:scaleType="fitXY"
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="fill_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>
编辑后的截图:
【问题讨论】:
-
这些设备是什么 API 版本?在版本 18 (=4.3) 之前,RelativeLayout 中存在测量错误
-
他们都在使用 4.2.2 或更低版本(知道解决方法/修复可能是什么吗?)
-
不应该用
match_parent代替fill_parent吗? -
在 XML 中的哪一点? (我在哪里都在使用 fill_parent?)
-
@user3113035 你试过下面的代码吗?
标签: android xml thumbnails android-ui android-xml