Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does LinearLayout have a max height?

I have a vertical linearlayout that won't stretch beyond a certain limit.

This is the layout with centerCrop in the imageview http://tinypic.com/r/20nm6s/5

This is the layout with no crop set (so it should be full width and huge) http://tinypic.com/r/vzk7kw/5

So my thought is that there is some implicit max height that I'm not seeing in my layout but I can't see where it is, can you spot my error?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@drawable/dropshadow"
            >
        <TextView
                android:id="@+id/heading"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                />
        <ImageView
            android:id="@+id/featuredimage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxHeight="1000dp"
            android:scaleType="centerCrop"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />
    </LinearLayout>
</RelativeLayout>
like image 586
bungleofsketches Avatar asked Oct 03 '13 16:10

bungleofsketches


People also ask

Which is better LinearLayout or RelativeLayout?

RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

What is difference between LinearLayout and RelativeLayout?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions.

What is the difference between Framelayout and LinearLayout?

Frame Layout: This is designed to block out an area on the screen to display a single item. Linear Layout: A layout that arranges its children in a single column or a single row. Relative Layout: This layout is a view group that displays child views in relative positions.

Is ConstraintLayout faster than LinearLayout?

Results show that the fastest layout is Relative Layout, but difference between this and Linear Layout is really small, what we can't say about Constraint Layout. More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout.


1 Answers

The "implicit" max height of the layout is the height of its parent. Since you're using wrap_content on both layouts, that means the parent is effectively the screen area, minus whatever other views you're using (such as the TextView). Unless you place it in a scrolling container, such as a ScrollView, it won't ever exceed the size of the screen.

The reason your ImageView isn't showing up "full width and huge" when you remove the crop is because the default scaleType for an ImageView is fitCenter. This particular view is bounded by the layout's width, so it shrinks the image while maintaining aspect ratio.

like image 58
Geobits Avatar answered Oct 05 '22 01:10

Geobits