Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding not working Android

The following code is from the layout I have been designing for my app. The problem is, Button is overlapping a PlainText box so I added padding in the button code as shown below but the preview is still showing Button to overlap the textbox. What is problem? Am I missing something?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:padding="25dp" >

<ScrollView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="30"
>

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
>
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText5"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/textView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText6"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />
</LinearLayout>
</ScrollView>

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_weight="40">
<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="20dp"
    android:text="Button" />
</LinearLayout>

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="30"
    android:orientation="vertical">
<AnalogClock
    android:id="@+id/analogClock1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</LinearLayout>

Thanks for your help!

like image 540
Alfred James Avatar asked Aug 05 '12 12:08

Alfred James


People also ask

What is Android padding?

Padding in Android is used to add a blank space between a view and its contents. Margins, on the other hand, are used to add a space between two different views.

What is padding and margin in Android?

Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent). Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object.

What is the difference between margin and padding in Android layout * 1 point?

Margin specifies the space left on four sides in the layout and padding specifies the exact position where the element going to be taking place in the layout.


1 Answers

It seems you want to separate two Views. You should use margin instead of padding in ur views.

android:layout_marginLeft="10dp"

You can give margin at left,right, top, bottom according to your need.

like image 99
AAnkit Avatar answered Nov 02 '22 19:11

AAnkit