Android Frequently Asked Questions

This post will collect most popular android Frequently Ask Questions from the internet. And provide answers to them. The answer is short and effect.

1. How To Align Buttons With Same Height?

Buttons before align with same height.

button not align with same height

For each button add below xml attributes.

android:layout_height="match_parent"
android:layout_gravity="fill_vertical"

Buttons with above attributes.

button align with same height

<Button
 android:id="@+id/buttonStartChronometer"
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:layout_gravity="fill_vertical"
 android:text="Start" />

2. How To Make Button Text Regular Case (Not All Upper case)?

button align center in horizontal

Add below button widget attribute. Or use ButtonInstance.setAllCaps(false) in java source code.

android:textAllCaps="false"

After set above attribute.

button text regular case

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:textAllCaps="false" />

3. How To Make One Button Align Center In Horizontal?

button align left 

Add below button xml attribute.

android:layout_gravity="center_horizontal"

After add above attribute.

button align center in horizontal

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:textSize="60sp"
    android:layout_gravity="center_horizontal" />

4. How To Make Chronometer Horizontal Align Center?

chronometer horizontal align left

Add gravity attribute for Chronometer widget in layout xml file.

android:gravity="center_horizontal"

After add gravity=”center_horizontal”.

chronometer horizontal align center

<Chronometer
    android:id="@+id/chronometerExample"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"/>

5. How To Add Scroll Bar To LinearLayout?

LinearLayout can not add scroll bar, if you want to scroll it’s content, you should contain the LinearLayout in a scroll component such as ScrollView as below.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        .....................
    </LinearLayout>
</ScrollView>
(Visited 119 times, 1 visits today)
READ :   Android Snackbar Example

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.