Layout is streching while cicking on InputView (Showing the keybad) - android

I have an little issue related to the layout which is stretching when the keypad appears clicking on an InputView.
This is how the layout looks before clicking on ImageView:
Before
This how the layout looks after :
After
As you can the layout moves.
[EDIT] above XML layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:weightSum ="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:id="#+id/imgGameStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="#+id/txtGameStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:layout_gravity="center_vertical"
android:text="Status..."/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="#+id/txtInvite"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lib_choose_number"
android:layout_gravity="center_vertical"
android:layout_weight="7"/>
<EditText
android:id="#+id/edtNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLength="4"
android:inputType="number"
android:paddingRight="4dp"
android:layout_gravity="center_vertical"
android:layout_weight="2" />
<Button
android:id="#+id/btnSend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="3"
android:text="#string/lib_send"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="#+id/imgBtn0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_weight="1"
android:background="#color/green"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="#+id/imgBtn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:layout_weight="1"
android:background="#color/green"/>
<Button
android:id="#+id/imgBtn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:layout_weight="1"
android:background="#color/green"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="5">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
your help please.

My guess is that your empty listview pushes up the buttons, when it has been pushed up by the keyboard.
Insert
android:windowSoftInputMode="stateHidden|adjustNothing"
in your activity in the manifest like so:
<activity
android:name=".activities.MyActivity"
android:windowSoftInputMode="stateHidden|adjustNothing">
</activity>

Insert
android:windowSoftInputMode="stateHidden|adjustNothing"
in your activity in the manifest like so:
<activity
android:name=".activities.MyActivity"
android:windowSoftInputMode="stateHidden|adjustNothing">
</activity>

Related

why specifying space between buttons in linear layout doesn't work?

I want some space between two buttons in my layout, but for some reason, my xml doesn't seem to work.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/btnAnswer_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/T1_Ans1"
android:layout_margin="2dp"
android:background="#color/answerRed"
android:textColor="#color/textColor"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnAnswer_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/T1_Ans2"
android:layout_margin="2dp"
android:background="#color/answerBlue"
android:textColor="#color/textColor"
android:textStyle="bold"
android:layout_marginTop="50dp"/>
</LinearLayout>
The result looks like this:
Try this :--
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/btnAnswer_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/T1_Ans1"
android:layout_margin="2dp"
android:background="#color/answerRed"
android:textColor="#color/textColor"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnAnswer_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/T1_Ans2"
android:background="#color/answerBlue"
android:textColor="#color/textColor"
android:textStyle="bold"
android:layout_marginTop="50dp"/>
</LinearLayout>
try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/btnAnswer_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/T1_Ans1"
android:layout_margin="2dp"
android:background="#color/answerRed"
android:textColor="#color/textColor"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnAnswer_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/T1_Ans2"
android:background="#color/answerBlue"
android:textColor="#color/textColor"
android:textStyle="bold"
android:layout_marginTop="50dp"/>
</LinearLayout>

Android: Place 4 buttons on RelativeLayout

I am trying to place 4 buttons to fill all the relative layout.. I want each button have width and height till the center of the RelativeLayout (with about 2dp space between them).. I don't think that I can explain it very good, so I have made an image and here is the code I have made... Any ideas?? Thank you!! The view right now is:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp"
android:layout_marginTop="10dp"
android:id="#+id/textView" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/relativeLayout"
android:weightSum="1">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Try this code. I used two linear layouts instead of one relative layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
<LinearLayout
android:orientation="horizontal"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="Button" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Fill up blank space, layout issue

I am creating a simon says app and it's going well except the layout.
As you can see on the image below I have no idea how to get my buttons like the example on the right.
I have tried many things but none of them worked, I'd just like that the buttons auto fill up the space they get.
My XML file looks like this (left example):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
tools:context="com.example.xyz.MainActivity" >
<RelativeLayout
android:id="#+id/row_one"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gameScore" />
<TextView
android:id="#+id/turn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Who&apos;s turn is it?" />
</RelativeLayout>
<LinearLayout
android:id="#+id/row_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row_one" >
<Button
android:id="#+id/green"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:background="#drawable/green_button"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Green"
android:textColor="#ffffff" />
<Button
android:id="#+id/red"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#drawable/red_button"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Red"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/row_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row_two"
android:layout_marginTop="2dp" >
<Button
android:id="#+id/yellow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:background="#drawable/yellow_button"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Yellow"
android:textColor="#ffffff" />
<Button
android:id="#+id/blue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#drawable/blue_button"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Blue"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:onClick="startGame"
android:text="#string/gameStatus_start" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Thank you guys in advance!
You can use this one also:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical"
android:paddingTop="10dp" >
<LinearLayout
android:id="#+id/row_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="30dp" >
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gameScore" />
<TextView
android:id="#+id/turn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Who&apos;s turn is it?" />
</LinearLayout>
<LinearLayout
android:id="#+id/row_two"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" >
<Button
android:id="#+id/green"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:background="#00ff00"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Green"
android:textColor="#ffffff" />
<Button
android:id="#+id/red"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#ff0000"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Red"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/row_three"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_marginTop="2dp" >
<Button
android:id="#+id/yellow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:background="#ddaa00"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Yellow"
android:textColor="#ffffff" />
<Button
android:id="#+id/blue"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#0000ff"
android:onClick="simon_onClick"
android:padding="3dp"
android:text="Blue"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:orientation="vertical"
android:layout_gravity="bottom"
>
<Button
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:onClick="startGame"
android:text="gameStatus_start" />
</LinearLayout>
Can you use LinearLayout(Vertical) as root layout?

align three children left, right and center within LinearLayout

Maybe a duplicate, but I haven't found a solution yet. So, I have a vertical LinearLayout with a header which is a horizontal layout and a main content section (FrameLayout). Within the header I got three children of which one should be left align, the other one right aligned and the third on should fill the space in between.
I think I have to use a RelativeLayout instead of a LinearLayout, but if I do so, it fill's the parent completely and nothing else is visible.
Any suggestion? Basically the two button inside the red rectangle should be aligned to the right.
Here's the XML.
<LinearLayout
android:id="#+id/sort_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:text="#string/sort_by"
android:textColor="#color/white80"
android:textSize="20sp" />
<RadioGroup
android:id="#+id/view_group"
style="#android:style/ButtonBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/background_dark"
android:orientation="horizontal"
android:padding="0dp" >
<ImageButton
android:id="#+id/btn_view_grid"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:onClick="onShowGrid"
android:src="#drawable/ic_action_view_as_grid" />
<ImageButton
android:id="#+id/btn_view_list"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:onClick="onShowGrid"
android:src="#drawable/ic_action_view_as_list" />
</RadioGroup>
<RadioGroup
android:id="#+id/sort_group"
style="#android:style/ButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_dark"
android:gravity="center"
android:orientation="horizontal"
android:padding="0dp" >
<Button
android:id="#+id/btn_sort_popular"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_popular"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_new"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_newest"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_hard"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_hardest"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_easy"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_easiest"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
</RadioGroup>
</LinearLayout>
<FrameLayout
android:id="#+id/preview_fragment"
android:background="#android:color/holo_green_dark"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
something similar may help
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/sort_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:text="sort_by"
android:textSize="20sp" />
<RadioGroup
android:id="#+id/sort_group"
style="#android:style/ButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_dark"
android:gravity="center"
android:orientation="horizontal"
android:padding="0dp" >
<Button
android:id="#+id/btn_sort_popular"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="sort_popular"
android:textColor="#FFFF"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_new"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:textColor="#FFFF"
android:text="sort_newest"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_hard"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:textColor="#FFFF"
android:text="sort_hardest"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_easy"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:textColor="#FFFF"
android:text="sort_easiest"
android:textSize="20sp" />
</RadioGroup>
<LinearLayout
android:id="#+id/sort_layout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal"
android:paddingBottom="10dp" >
<ImageButton
android:id="#+id/btn_view_grid"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_weight="1"
android:gravity="right"
android:onClick="onShowGrid"
android:src="#drawable/ic_action_view_as_grid" />
<ImageButton
android:id="#+id/btn_view_list"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_weight="1"
android:gravity="right"
android:onClick="onShowGrid"
android:src="#drawable/ic_action_view_as_list" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/preview_fragment"
android:background="#android:color/holo_green_dark"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I finally figured out how to achieve this. I had to use the following values inside a RelativeLayout instead of a LinearLayout correctly:
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/view_group"
android:layout_toRightOf="#+id/label_sort"
Here's the XML:
<RelativeLayout
android:id="#+id/sort_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/label_sort"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:fontFamily="sans-serif-condensed"
android:text="#string/sort_by"
android:gravity="center"
android:textColor="#color/white80"
android:textSize="20sp" />
<RadioGroup
android:id="#+id/view_group"
style="#android:style/ButtonBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#android:color/background_dark"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:padding="0dp" >
<ImageButton
android:id="#+id/btn_view_grid"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:onClick="onShowGrid"
android:src="#drawable/ic_action_view_as_grid" />
<ImageButton
android:id="#+id/btn_view_list"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:onClick="onShowList"
android:src="#drawable/ic_action_view_as_list" />
</RadioGroup>
<RadioGroup
android:id="#+id/sort_group"
style="#android:style/ButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/view_group"
android:layout_toRightOf="#+id/label_sort"
android:background="#android:color/background_dark"
android:gravity="center"
android:orientation="horizontal"
android:padding="0dp" >
<Button
android:id="#+id/btn_sort_popular"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_popular"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_new"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_newest"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_hard"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_hardest"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
<Button
android:id="#+id/btn_sort_easy"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:onClick="onSortChanged"
android:text="#string/sort_easiest"
android:textColor="#drawable/sort_button_selector"
android:textSize="20sp" />
</RadioGroup>
</RelativeLayout>
<FrameLayout
android:id="#+id/preview_fragment"
android:background="#android:color/holo_green_dark"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

how to set in textview same sizes

I need to implement textview with equal sizes for 3 character, but i have got some problem if i add:
This four buttons have got diferent sizes ...but i dont know why, and how can i change
MOD
_X_
_(_
_5_
_ is white spaces..
There is xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1dp" >
<TextView
android:id="#+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" >
</TextView>
<TextView
android:id="#+id/item_text_Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp" >
</TextView>
End there is picture of my problem:
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="4"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
</LinearLayout>
Give your TextView a fix size width by changing layout_width from wrap_content to some fix dp size like 30dp
Example:
<TextView
android:id="#+id/item_text"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:text="MOD"
android:textSize="12sp" >
</TextView>
look like you try to make button in table like in XML???
don`t know if this can help you, but when i try to make same precise width i use this...
here`s the explanation
create 1 linear layout with vertical orientation (so, everytime you add new item, it will placed to down)
inside it, insert linear layout with horizontal orientation... (insert as many row you want, in you case looks like you need 5 linear layout with horizontal orientation)
after that, insert you button / textview inside the linear layout (horizontal orientation), so your button / text will placed horizontaly.
if you want to change row, just insert the button / textview inside another linear layout (horizontal orientation).
after you insert all, set the linear layout (horizontal value) with this code
android:weightSum="5"
why 5? because in your case, u make 5 column.
and dont forget to set the width = fill parent.
after that set the button /textview inside the linearlayout (horizontal) with add this code
android:layout_weight="1"
and dont forget to change the width with fill parent.
with this, i can make precise width in every row. next step you can set the margin to make your button / textview looks good.
hope this can help you...
=====================================
here`s the code if you confuse with my explanation
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tes.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button22"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button21"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button24"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button23"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button20"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button17"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button16"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button19"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button18"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button15"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button14"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button13"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button07"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button06"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button09"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button08"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button05"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<Button
android:id="#+id/Button04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
</LinearLayout>

Categories

Resources