This post will collect the most popular android Frequently Ask Questions from the internet. And provide answers to them. The answer is short and effective.
1. How To Align Buttons With Same Height?
The below image shows the buttons before aligning with the same height.
For each button add the below XML attributes.
android:layout_height="match_parent" android:layout_gravity="fill_vertical"
The below image shows the buttons with the above attributes.
<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)?
Add below button widget attribute. Or use ButtonInstance.setAllCaps(false)
in java source code.
android:textAllCaps="false"
The below image is after setting the above attribute to the Button object.
<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?
Add below button XML attribute.
android:layout_gravity="center_horizontal"
After adding the above attribute.
<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?
Add the below gravity attribute for the Chronometer widget in the layout XML file.
android:gravity="center_horizontal"
After add gravity=”center_horizontal”.
<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 a 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>