android - Why are there gaps on the right and left of linear layout? -


i learning android lately , bothers me.

enter image description here

somehow gap on left , right can't removed. have tried changing layout:margin right& left linear layout owns 4 buttons "-10dp". however, stretches selection box. example, number "9" got moved further left inside button. it's button indeed stretched stretched part invisible or what.

this stupid question can't seem find answer. please help!!

<?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="example.org.bettercalculator.mainactivity"     tools:showin="@layout/activity_main"     android:background="#89cf27">       <edittext         android:layout_width="match_parent"         android:layout_height="120dp"         android:inputtype="numberdecimal"         android:ems="10"         android:background= "@android:color/transparent"         android:id="@+id/edittext"         android:gravity="center_vertical|right"         android:textsize="40dp"         android:layout_alignparenttop="true" />      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="50dp"         android:id="@+id/linearlayout"         android:layout_below="@+id/linearlayout2"         android:layout_alignparentright="true"         android:layout_alignparentend="true"         android:layout_alignparentleft="false"         android:paddingleft="-20dp">          <button             style="?android:attr/buttonstylesmall"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="9"             android:id="@+id/button"             android:layout_weight="1"             android:layout_marginright="-8dp"             android:layout_marginleft="-8dp" />          <button             style="?android:attr/buttonstylesmall"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="8"             android:id="@+id/button2"             android:layout_weight="1"             android:layout_marginright="-8dp" />          <button             style="?android:attr/buttonstylesmall"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="7"             android:id="@+id/button3"             android:layout_weight="1"             android:layout_marginright="-8dp" />          <button             style="?android:attr/buttonstylesmall"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="*"             android:id="@+id/button4"             android:layout_weight="1" />      </linearlayout>      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="50dp"         android:layout_below="@+id/edittext"         android:layout_centerhorizontal="true"         android:id="@+id/linearlayout2"></linearlayout>   </relativelayout> 

your releative layout has paddings on it. because it's parent viewgroup, child views rendered in area paddings.

android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" 

Comments