【发布时间】:2016-04-14 00:36:03
【问题描述】:
每当我在设计器图面上添加一个新的容器视图并将layout:width 和layout:height 设置为wrap_content 时,容器视图的大小都会超出其应有的大小,如下所示。
我应该怎么做才能解决这个问题?
content_main.xml的代码sn-p
编辑:可能与上图略有不同,但问题仍然相同。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.dance2die.myapplication.MainActivity"
tools:showIn="@layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:padding="0dp" />
</RelativeLayout>
【问题讨论】:
-
我相信会发生这种情况是因为列表视图需要先填充列表视图项,然后列表视图才能计算其高度和宽度。因此,如果没有测量的高度和宽度,它就无法按照您的意愿包装内容。除了用 xml 中的示例内容填充列表视图之外,我认为没有其他好的方法可以解决此问题。
-
发布您的 XML 代码 sn-p 而不是在图像中提供。
标签: android-layout android-studio