Issue
I have been trying to make my first application using Android Studio. I tried many ways including layout_margin="-8dp"
but none of it seems to be able to remove the spaces between the buttons. I don't want the spaces in a Linear Layout to be present. Is it the natural characteristics of buttons and should I replace it with TextView and set onClick for it or is it possible to do with button also?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/RelativeLayoutTop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="@+id/Result"
android:layout_width="match_parent"
android:layout_height="100dp"
android:hint="Result"
android:gravity="right|bottom"
android:textSize="26sp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="500dp"
android:weightSum="5"
android:orientation="vertical"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="3">
<Button
android:id="@+id/clear"
android:text="CLEAR"
android:textColor="#06279B"
android:textSize="35sp"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
I expect no spaces between buttons. But I can clearly see the white color of the Linear Layout.
Solution
You can use Table Layout for this as shown below,...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/RelativeLayoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/Result"
android:layout_width="match_parent"
android:layout_height="200dp"
android:hint="Result"
android:gravity="right|bottom"
android:textSize="26sp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLEAR"
android:textColor="@color/accent"
android:textSize="@dimen/margin_30dp"
android:gravity="center"
android:textStyle="bold"
android:background="@color/primary_light"/>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/simpleTableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="@+id/firstRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="7"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="8"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="9"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="+"
android:textColor="@color/accent"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
</TableRow>
<TableRow
android:id="@+id/secondRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="4"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="5"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="6"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="-"
android:textColor="@color/accent"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
</TableRow>
<TableRow
android:id="@+id/thirdRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="1"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="2"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="3"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="x"
android:textColor="@color/accent"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
</TableRow>
<TableRow
android:id="@+id/fourthRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="0"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="."
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="="
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
<TextView
android:layout_height="@dimen/margin_100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/temp_grey"
android:text="/"
android:textColor="@color/accent"
android:gravity="center"
android:textSize="@dimen/margin_30dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
Hope this will help you!! Thanks!!
Answered By - Happy Bhimani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.