我是一个活动,其中包含带有电影海报的gridview和带有电影标题的一些叠加文本。
我为平板电脑制作了一个额外的布局,同时还显示了同一活动中所选电影的详细信息。
问题在于,当我在横向模式下使用平板电脑时,由于某种原因,第一行元素会垂直扩展,占用所有可用空间。
这是一张图片,让您知道问题所在:
http://postimg.org/image/rgwakvlq3/
这是我的平板电脑布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" tools:ignore="MergeRootFrame">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.madelenko.movierating.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
tools:context="com.example.madelenko.movierating.MainActivity">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:numColumns="@integer/column_count"
android:gravity="center"
android:verticalSpacing="@dimen/grid_vert_spacing"
android:stretchMode="columnWidth"/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/movie_detail_container"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
这是包含每个电影海报中元素的相对布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/grid_element_parent">
<!-- View to be populated with a movie poster-->
<ImageView
android:id="@+id/image_thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!--View to be populated with the movie's title and rating-->
<TextView
android:layout_width="@integer/image_width"
android:layout_height="@dimen/text_overlay_height"
android:background="#00000000"
android:textColor="#00000000"
android:gravity="center"
android:layout_centerHorizontal="true"
android:id="@+id/overlay_text"/>
</RelativeLayout>
正确的用户界面应如下所示:
http://postimg.org/image/939s90085/
(但是用3个col而不是2个)
我该如何解决这个问题?
非常感谢。
答案 0 :(得分:1)
将此行添加到ImageView
:
android:adjustViewBounds="true"