每当我在设计器表面添加新的容器视图并将layout:width
和layout:height
设置为wrap_content
时,容器视图大小超出了它应该如下所示的大小。在Android Studio预览版中,容器伸展超越
我该怎么做才能解决这个问题?的content_main.xml
编辑
代码片段:可能是从上图中,但仍是同样的问题,有点不同。
<?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>
我相信会发生这种情况,因为在listview可以计算它的高度和宽度之前,需要使用列表视图项来填充listview。因此,如果没有测量的高度和宽度,则无法按照您的要求包装内容。我不认为有一种好的方法可以解决这个问题,而不是用xml中的示例内容填充listview。 –
发布您的XML代码片段,而不是在图像中提供。 –