match_parent并且未按预期填充-Android / XML
作者:互联网
我在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 Butterfly的屏幕截图:
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>
编辑后的截图:
解决方法:
如果要扩展ImageView,请尝试应用此方法:
android:scaleType="fitXY"
或在Javacode中
imageView.setScaleType(ScaleType.FIT_XY);
2)应用上述代码,例如:
<com.example.project.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:scaleType="fitXY"
android:focusableInTouchMode="false"
android:gravity="center"
android:src="@drawable/ic_launcher" />
编辑已更改:
android:adjustViewBounds="true"
至
android:adjustViewBounds="false"
标签:android-xml,android-ui,thumbnails,xml,android 来源: https://codeday.me/bug/20191122/2059007.html