Reputation: 413
The two
button
in the following code, were set to wrap_content
and no padding. However, there is still some padding in the vertical orientation. If I set the android:layout_height
to a fixed parameter, the padding could disappear. But I do want to use wrap_content
instead of a fixed height.
EDIT: Now, I have to use DIP, which is not recommended, as text size to ensure the text in the button while using a fixed height in DIP. Looking forward to a better solution!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="5dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account_balance"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tvBa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="@drawable/video_list_price"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/record_selector"
android:gravity="center"
android:textColor="#ffffffff"
android:text="@string/charge_record"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@drawable/charge_selector"
android:gravity="center"
android:textColor="#ffffffff"
android:text="@string/charge"/>
</LinearLayout>
Upvotes: 1
Views: 11056
Reputation: 4743
Add minHeight and minWidth to your button as 0dp
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/record_selector"
android:gravity="center"
android:textColor="#ffffffff"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="@string/charge_record"/>
Upvotes: 0
Reputation: 12626
Remove this line:
android:layout_weight="1.0"
And change the 0dp value to wrap_content
--EDITED
You have 2 potential sources of the padding: first one is initial button backgroud sizes - it will not be scaled down, only up
Second one is the default style for button - just set padding = 0dp
Upvotes: 0
Reputation: 7071
By default container content align top.
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account_balance"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tvBa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="@drawable/video_list_price"/>
</LinearLayout>
</LinearLayout>
This content is taking more height compare to Button.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/record_selector"
android:gravity="center"
android:textColor="#ffffffff"
android:text="@string/charge_record"/>
So actually buttons are not having padding now, but it is taking more space due to first item of your root LinearLayout.
Add one more attribute in your root LinearLayout. android:gravity="center_vertical"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="#756846">
Upvotes: 0