How to include blank view in Layout - android

i design a login view. I want to insert a fragment layout which is placed at the center of parent view. I hard code to input some fragment layout to make this effect. But, does there exist better way to do this.
This is my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="2"
android:orientation="horizontal">
<FrameLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
<FrameLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2">
</FrameLayout>
<FrameLayout
android:id="#+id/login_frame"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
Thanks you.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical">
<TableRow
android:id="#+id/row1"
android:layout_marginTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtUserName"
android:layout_marginLeft="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Username"
android:textSize="16sp" />
</TableRow>
<TableRow
android:id="#+id/row2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:inputType="text"
android:id="#+id/editUsername"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_weight="2"
android:singleLine="true"
android:layout_marginLeft="50dp"
android:layout_marginTop="2dip"
android:layout_marginRight="50dp"
android:padding="10dp"/>
</TableRow>
<TableRow
android:id="#+id/row3"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:layout_marginLeft="50dp"
android:text="password"
android:textSize="16sp" />
</TableRow>
<TableRow
android:id="#+id/row4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:inputType="textPassword"
android:id="#+id/editPassword"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_weight="2"
android:layout_marginTop="2dip"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:padding="10dp"
android:password="true"
android:singleLine="true"/>
</TableRow>
<TableRow
android:id="#+id/row5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/chkRememberPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="52dp"
android:padding="10dp"
android:textSize="15sp"
android:text="rememberme"
/>
</TableRow>
<TableRow
android:id="#+id/row6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/login"
android:layout_width="100dp"
android:layout_height="35dp"
android:text="login"
android:textStyle="bold"
android:layout_marginLeft="102dp"/>
</TableRow>

Related

Table layout overlaps Linear Layout in Android studio

I am having issue aligning my contents in a proper order. When I test my app in emulator, I discovered table layout overlapping the Linear layout. I have tried some solutions but none worked.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#drawable/table_background2" android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout android:gravity="center" android:id="#+id/headerpicture" android:background="#color/loginheader" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true">
<TextView android:textSize="20sp" android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="#string/fixed_header"/>
<ImageView android:id="#+id/imgLeftBack" android:layout_width="35dp" android:layout_height="35dp" android:src="#drawable/arrow_left_green" android:layout_alignParentRight="true" android:onClick="goBack" android:contentDescription="#string/empty"/>
</RelativeLayout>
<RelativeLayout android:gravity="center" android:id="#+id/footer" android:background="#color/loginheader" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true">
<TextView android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="#string/copyright" android:ems="8"/>
</RelativeLayout>
<TableLayout android:layout_gravity="top" android:id="#+id/tableLayout1" android:background="#drawable/gradient" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:layout_below="#+id/headerpicture">
<TableRow android:id="#+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:textColor="#color/list_item_text" android:ellipsize="none" android:layout_gravity="top" android:id="#+id/textViewUsernamePicture" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="#dimen/text_view_marginLeft" android:layout_marginTop="#dimen/text_view_marginTop" android:text="#string/pre_election_usernameLbl" android:layout_weight="1"/>
<EditText android:layout_gravity="left|center_vertical|center_horizontal|center" android:id="#+id/txtUsernamePicture" android:layout_width="wrap_content" android:layout_height="#dimen/edit_text_height" android:layout_marginLeft="#dimen/text_view_marginLeft" android:ems="8" android:layout_weight="3" android:inputType="text"/>
</TableRow>
<TableRow android:layout_marginBottom="10dp" android:id="#+id/tableLayout2Row9" android:layout_width="wrap_content" android:layout_height="wrap_content">
<EditText android:gravity="top|left|center_vertical|center_horizontal|center" android:layout_gravity="left|center_vertical|center_horizontal|center" android:id="#+id/txtTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="3" android:inputType="text" android:hint="Incident Title" android:layout_marginLeft="#dimen/table_marginLeft"/>
</TableRow>
</TableLayout>
<ImageView android:layout_marginBottom="0dp" android:layout_gravity="center" android:id="#+id/ImgPicture" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="#dimen/text_view_marginTop" android:src="#drawable/picture_placeholder" android:layout_below="#+id/tableLayout1" android:contentDescription="#string/empty"/>
<TableLayout android:layout_gravity="top" android:id="#+id/tableLayout2" android:background="#drawable/gradient" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:layout_below="#+id/ImgPicture">
<TableRow android:layout_marginBottom="10dp" android:id="#+id/tableLayout2Row13" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:textColor="#color/list_item_text" android:ellipsize="none" android:layout_gravity="top" android:id="#+id/textViewPriorityIncident" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="#dimen/text_view_marginLeft" android:layout_marginTop="#dimen/text_view_marginTop" android:text="#string/incident_priorityLbl" android:layout_weight="1"/>
<Spinner android:entries="#array/incident_priority_arrays" android:id="#+id/spinnerPriorityIncident" android:layout_width="match_parent" android:layout_height="wrap_content" android:prompt="#string/incident_priority_prompt"/>
</TableRow>
<TableRow android:layout_marginBottom="10dp" android:id="#+id/tableLayout2Row5" android:layout_width="wrap_content" android:layout_height="wrap_content">
<EditText android:gravity="top|left|center_vertical|center_horizontal|center" android:layout_gravity="left|center_vertical|center_horizontal|center" android:id="#+id/txtCommentsIncident" android:scrollbars="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="#dimen/table_marginLeft" android:lines="4" android:minLines="3" android:ems="8" android:maxLength="#string/comments_length" android:layout_weight="3" android:inputType="textMultiLine" android:hint="Comment"/>
</TableRow>
</TableLayout>
<LinearLayout android:id="#+id/btnsHolder" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="#+id/tableLayout2" android:layout_above="#id/footer">
<Button android:background="#color/red" android:textColor="#color/redtextxolor" android:tint="#color/redtextxolor" android:id="#+id/btnSaveImage" android:paddingLeft="#dimen/btn_padding_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="#string/btnBack" android:drawableLeft="#android:drawable/ic_media_previous" android:onClick="goBack"/>
<Button android:background="#color/btn" android:textColor="#color/btntextcolor" android:tint="#color/btntextcolor" android:layout_gravity="center" android:id="#+id/btnTakePicture" android:paddingLeft="10sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="#string/btnSnap" android:drawableLeft="#android:drawable/ic_menu_camera" android:onClick="captureImage"/>
<Button android:background="#color/snap" android:textColor="#color/white" android:tint="#color/white" android:layout_gravity="center" android:id="#+id/btnSendPicture" android:paddingLeft="10sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="#string/btnSendSnap" android:drawableLeft="#android:drawable/ic_menu_send" android:onClick="sendForm"/>
</LinearLayout>
</RelativeLayout>
First off that is the worst formatting I have ever seen lol buuut inside the linear layout just set it to be under the table layout
like this
<TableLayout
android:id="#+id/mytable"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
<LinearLayout
android:id="#+id/mylinear"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/mytable">
</LinearLayout>
notice the android:layout_below="#+id/mytable"> . which is the id i gave to the table view just do that then they shouldnt overlap, now in your code this would mean you're going to have to give an id to the table layout in order to do this
dont mind the height and width I gave the linear view all you should worry about if the layout_below the rest was just me hitting enter to fill
<LinearLayout
android:orientation="horizontal"
android:background="#drawable/gradient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp" >
<Spinner
android:entries="#array/incident_priority_arrays"
android:id="#+id/spinnerPriorityIncident"
android:layout_width="wrap_content"\
android:layout_height="wrap_content"
android:layout_gravity="center"
android:prompt="#string/incident_priority_prompt"/>
<TextView
android:textColor="#color/list_item_text"
android:ellipsize="none"
android:id="#+id/textViewPriorityIncident"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/text_view_marginLeft"
android:layout_marginTop="#dimen/text_view_marginTop"
android:text="#string/incident_priorityLbl" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:gravity="center"
android:id="#+id/txtCommentsIncident"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/table_marginLeft"
android:lines="4"
android:minLines="3"
android:ems="8"
android:maxLength="#string/comments_length"
android:inputType="textMultiLine"
android:hint="Comment"/>
</LinearLayout>
<LinearLayout android:id="#+id/btnsHolder"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tableLayout2"
android:layout_above="#id/footer">
<Button
android:background="#color/red"
android:textColor="#color/redtextxolor"
android:tint="#color/redtextxolor"
android:id="#+id/btnSaveImage"
android:paddingLeft="#dimen/btn_padding_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/btnBack"
android:drawableLeft="#android:drawable/ic_media_previous"
android:onClick="goBack"/>
<Button
android:background="#color/btn"
android:textColor="#color/btntextcolor"
android:tint="#color/btntextcolor"
android:layout_gravity="center"
android:id="#+id/btnTakePicture"
android:paddingLeft="10sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/btnSnap"
android:drawableLeft="#android:drawable/ic_menu_camera"
android:onClick="captureImage"/>
<Button
android:background="#color/snap"
android:textColor="#color/white"
android:tint="#color/white"
android:layout_gravity="center"
android:id="#+id/btnSendPicture"
android:paddingLeft="10sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/btnSendSnap"
android:drawableLeft="#android:drawable/ic_menu_send"
android:onClick="sendForm"/>
</LinearLayout>

Replacing TableLayout with ListView?

I am currently using TableLayout inside ScrollView and Multiple ListView inside TableRows for getting following results.
With following XML
<?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" >
<include layout="#layout/progress_bar" />
<ScrollView
android:id="#+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tr_lbl_topSongs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_orange"
android:padding="5dp" >
<TextView
android:id="#+id/tv_lbl_topSongs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Top Songs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/app_white" />
</TableRow>
<TableRow
android:id="#+id/tr_content_topSongs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >
<ListView
android:id="#+id/lv_topSongs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:listSelector="#android:color/transparent" >
</ListView>
</TableRow>
<TableRow
android:id="#+id/tr_viewMore_topSongs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:background="#color/app_offwhite"
android:gravity="center_horizontal|center_vertical"
android:padding="5dp" >
<TextView
android:id="#+id/tv_viewMore_topSongs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="View More"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/app_gray" />
</TableRow>
<TableRow
android:id="#+id/tr_lbl_topVideos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_orange"
android:padding="5dp" >
<TextView
android:id="#+id/tv_lbl_topVideos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top Videos"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/app_white" />
</TableRow>
<TableRow
android:id="#+id/tr_content_topVideos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >
<ListView
android:id="#+id/lv_topVideos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:listSelector="#android:color/transparent" >
</ListView>
</TableRow>
<TableRow
android:id="#+id/tr_viewMore_topVideos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:background="#color/app_offwhite"
android:gravity="center_horizontal|center_vertical"
android:padding="5dp" >
<TextView
android:id="#+id/tv_viewMore_topVideos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="View More"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/app_gray" />
</TableRow>
<TableRow
android:id="#+id/tr_lbl_topRingtones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_orange"
android:padding="5dp" >
<TextView
android:id="#+id/tv_lbl_topRingtones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top Ringtones"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/app_white" />
</TableRow>
<TableRow
android:id="#+id/tr_content_topRingtones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >
<ListView
android:id="#+id/lv_topRingtones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:listSelector="#android:color/transparent" >
</ListView>
</TableRow>
<TableRow
android:id="#+id/tr_viewMore_topRingtones"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
android:background="#color/app_offwhite"
android:gravity="center_horizontal|center_vertical"
android:padding="5dp" >
<TextView
android:id="#+id/tv_viewMore_topRingtones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="View More"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/app_gray" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
I done hacks on ListViews for Scroll issues created by Conflict of ScrollView and ListView. Now I realized that this is creating some mess with NavigationDrawer I want to shift to single ListView Approach. Is it possible? Any Example? Thanks in Advance.

I am getting perfect view in graphical layout but in avd it's not looking good. Is there any solution?

I am getting proper view in my graphical layout but when I see the output in avd it's not covering the whole screen. How can I make it proper? Can anyone help me.
Thanks in advance.
My landscape layout-land\main.xml
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0"
android:orientation="horizontal"
android:gravity="center"
>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="#string/Msg" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="30dp"
android:layout_weight="1"
android:singleLine="true"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/hint" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/txt_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="30dp"
android:layout_weight="1"
android:singleLine="true"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0">
<Button
android:id="#+id/btn_encry" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center_horizontal"
android:layout_marginLeft="75dp"
android:text="#string/EncryButton" /></LinearLayout>
</TableRow>
</TableLayout>
</AbsoluteLayout>

How to position a login box centered on application start?

I am new to Android and trying to build a login box, and experience some troubles. I created two textes (Username, Password) and two text-boxes next to them, to style a login box area.
But unfortunately the elements jump up and down in correlation with the upper and lower bars, that are shown when the user touches the screen.
How can I realize a centered login box?
Link: maximize image
Here is some code:
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout android:id="#+id/fullscreen_content_controls"
style="?buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/login_button" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:baselineAligned="false"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="false"
android:layout_alignParentBottom="false"
android:layout_centerInParent="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_username"
android:id="#+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:id="#+id/textView2"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_column="1" />
</TableRow>
</TableLayout>
</RelativeLayout>
</FrameLayout>
There is no need of Table Layout It simply done with relative and linearlayout.
http://www.androidhive.info/2011/10/android-login-and-registration-screen-design/
Use this -
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_username"
android:id="#+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:id="#+id/textView2"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_column="1" />
</TableRow>
</TableLayout>
</RelativeLayout>
<Button
android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:text="#string/login_button" />
</FrameLayout>
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_username"
android:id="#+id/textView" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:id="#+id/editText"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:id="#+id/textView2"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPassword"
android:ems="10"
android:layout_marginLeft="5dp"
android:id="#+id/editText3"/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:id="#+id/fullscreen_content_controls"
style="?buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/black_overlay">
<Button android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_button" />
</LinearLayout>
</LinearLayout>

Android: when wrap_content doesn't just wrap its content?

I have a following xml layout in my project (incidentally, if you notice something else that is also seemingly wrong/not so good yet, I'd appreciate you let me know about it!) and my problem is the attribute "wrap_contents" doesn't work at the last TextView ("EEE", txt4). Is there any regulation I overlook?
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="#+id/Table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="AAA"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/array1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="BBB"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:entries="#array/Tounyuhou" />
<EditText
android:id="#+id/edt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="numberSigned"/>
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="CCC" android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="18sp"/>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="DDD"
android:textColor="#color/white" />
<EditText
android:id="#+id/edt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center_vertical">
</EditText>
<TextView
android:id="#+id/txt4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="EEE"
android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="20sp"/>
</TableRow>
</TableLayout>
</merge>
here you define all the rows in same layout , but with different number of views, like row1 contain 2 , row2 contain 4 then row3 contain 3 views,
so it gives problem,
so my suggetion take different tablelayout for third row.
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="#+id/mainTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/mainTable_tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TableLayout
android:id="#+id/Table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="AAA"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/array1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="BBB"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:entries="#array/Tounyuhou" />
<EditText
android:id="#+id/edt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="numberSigned"/>
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="CCC" android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="18sp"/>
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:id="#+id/mainTable_tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TableLayout
android:id="#+id/Table2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/table2_tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="DDD"
android:textColor="#color/white" />
<EditText
android:id="#+id/edt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center_vertical">
</EditText>
<TextView
android:id="#+id/txt4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="EEE"
android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="20sp"/>
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
</merge>

Categories

Resources