Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: how do I add padding to a LinearLayout inside a FrameLayout

I have a FrameLayout with many children. One of the children is a LinearLayout. I want the width of the LinearLayout to match_parent but about 90% so; which means I want to add some sort of paddingLeft/Right or margingLeft/Right. But when I add the padding or margin, it is not applied in the Graphical Layout. How do I do this correctly?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:background="@color/red"
        android:marginLeft="20dp"
        android:marginRight="20dp"
        android:orientation="vertical" >
....
like image 216
user3093402 Avatar asked Dec 07 '22 03:12

user3093402


1 Answers

you have

android:marginLeft="20dp"
android:marginRight="20dp"

instead change it to:

android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"

If it still doesnot work, put this layout inside another layout and set the margins to the other layout.

like image 197
Rat-a-tat-a-tat Ratatouille Avatar answered Dec 10 '22 12:12

Rat-a-tat-a-tat Ratatouille