Friday, April 22, 2016

Containers stretch beyond in Android Studio preview

Leave a Comment

Whenever I add a new container view on the designer surface and sets both layout:width and layout:height to wrap_content, the container view size goes beyond what it should be as shown below.

What should I do to fix this issue?

Android Studio

Code snippet of content_main.xml

enter image description here

EDIT: Might be a bit different from image above but still the same issue.

<?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> 

5 Answers

Answers 1

Use

android:layout_width="match_parent" android:layout_height="match_parent"

Answers 2

A wild guess but try to use a scrollview instead of a relativelayout.

or within the layout so it will stay the same size when the listview is populated and doesn't stretch.

Answers 3

This is because of your app:layout_behavior="" try to change it or remove it,your container size wont go beyond.

Answers 4

Try changing the warp_contentto match_parent

<ListView     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/listView"     android:layout_alignParentTop="true"     android:layout_alignParentStart="true"     android:padding="0dp" /> 

Answers 5

There is nothing wrong with that.

The preview shows you just a preview of what it will be using a Simple 2-Line List item. It is stretched because you set it to wrap content so the ListView would actually be longer than your screen if there would be more than 8 items in it (at least in a preview on that device, maybe on a preview of a Nexus 6 you would see 10 items).

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment