How do I set spinner? In my code spinner and edit text box layout margin left and right is look equal in simulator but when I deploy on real device spinner look bigger form left and right side as compare to edit text box how do I set equal both edittext box and spinner in all screen?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0.2"
android:weightSum="1"
android:orientation="horizontal" >
<EditText
android:id="#+id/txtMobileNo"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="45dp"
android:layout_marginLeft="45dp"
android:layout_height="wrap_content"
style="?android:attr/buttonStyleSmall"
android:gravity="left"
android:hint="#string/MobileNo"
android:background="#ffffff"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:weightSum="1"
android:orientation="horizontal" >
<EditText
android:id="#+id/txtPinNo"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="45dp"
android:layout_marginLeft="45dp"
android:layout_height="wrap_content"
style="?android:attr/buttonStyleSmall"
android:inputType="textPassword"
android:gravity="left"
android:background="#ffffff"
android:singleLine="true"
android:hint="#string/PinNo"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:weightSum="1"
android:orientation="horizontal" >
<Spinner
android:id="#+id/lgnspinner"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:prompt="#string/network_prompt"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_marginTop="-15dp"
android:layout_marginBottom="-17dp"
android:layout_marginRight="41dp"
android:layout_marginLeft="41dp"
android:layout_height="wrap_content" />
</LinearLayout>
Related
For the below xml code weight sum is 4 i have divided into 4 parts .2 parts for displaying text and remaining 2 parts again divided into 2 parts . 1 part contains text and another part contains image .but for the send 2 parts are not displaying properly.
text of the second layout is moving left side .
Can any one help me
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4"
android:layout_marginTop="4dp"
android:paddingBottom="10dp"
android:id="#+id/outcomess"
android:layout_below="#+id/statuss">
<TextView
android:id="#+id/text_outcome"
style="#style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#+id/bill_district"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Outcome"
android:textStyle="bold"
android:layout_weight="2"
android:textColor="#color/gray"
android:textSize="15sp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/outcome"
style="#style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Interested"
android:layout_weight="1"
android:textColor="#color/gray"
android:textSize="15sp"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/image"
android:layout_weight="1"
android:src="#drawable/ic_thumb_up_black_24dp">
</ImageView>
</LinearLayout>
</LinearLayout>
> you mentioned weightSum="4" so add weight second Linearlayout
<LinearLayout
android:id="#+id/outcomess"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/statuss"
android:layout_marginTop="4dp"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:weightSum="4">
<TextView
android:id="#+id/text_outcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bill_district"
android:layout_weight="2"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Outcome"
android:textSize="15sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2"
android:weightSum="">
<TextView
android:id="#+id/outcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Not Interested"
android:textSize="15sp" />
<ImageView
android:id="#+id/image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1"
android:src="#drawable/car">
</ImageView>
</LinearLayout>
</LinearLayout>
I have the following requirement:
i> Consider a layout tab_container of height 40 dp.
ii> The layout is divided into two equal individual parts in a
horizontal manner.
iii>Within each individual layout , there is a TextView and EditText
The issue , for example , I enter a value 3 on edit_text_1 and then tap on edit_text_2 and enter 222, both the layouts shifts a bit (right or left) .
This issue occurs when value is entered on edit_text_2 and edit_text_1 is tapped.
<LinearLayout
android:id="#+id/tab_container"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:id="#+id/linear_layout_1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="#+id/txt_view_1"
style="#style/button_text_style_white_hdpi"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.6"
android:gravity="center"
android:text="Sample"
android:textSize="14sp"
continental:typeface="roboto_bold" />
<EditText
android:id="#+id/edit_text_1"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:layout_weight="0.4"
android:background="#color/White"
android:gravity="center_vertical"
android:inputType="number"
android:maxLength="3"
android:textColor="#android:color/black"
android:textIsSelectable="false"
android:textSize="14sp" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="#+id/txt_view_2"
style="#style/button_text_style_white_hdpi"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.6"
android:gravity="center"
android:text="Sample2"
android:textSize="14sp"
/>
<EditText
android:id="#+id/edit_text_2"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:layout_weight="0.4"
android:background="#color/White"
android:gravity="center_vertical"
android:inputType="number"
android:maxLength="3"
android:textColor="#android:color/black"
android:textIsSelectable="false"
android:textSize="14sp" >
<requestFocus />
</EditText>
</LinearLayout>
</LinearLayout>
Any suggestions will be helpful.
I am trying to allign 3 EditText boxes across the screen horizontally in my activity so that the user is able to enter data.
Currently the code that I am implementing doesnt allow the 3 boxes to fit on the screen. Only 1 box and half of the other are visible
How can I adjust my current code so that all 3 Edittext boxes are visible to the user?
Note: The button and textView at the bottom of the layout are also currently not visible, eventhough they should be under the 3 horizontally alligned Edittext boxes.
Current XML Layout:
<?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/tvSearchDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Enter Date to search..."
android:textSize="15dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/etEnterSpecificyear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="" >
</EditText>
<TextView
android:layout_width="3dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<EditText
android:id="#+id/etEnterSpecificMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="" >
</EditText>
<TextView
android:layout_width="3dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<EditText
android:id="#+id/etEnterSpecificDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="" >
</EditText>
</LinearLayout>
<Button
android:id="#+id/btnSearchDate"
android:layout_width="85dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Submit"
/>
<TextView
android:id="#+id/tvSearchResultsDate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="30"
android:minLines="5"
android:scrollbars="vertical"
android:text=" Results..."
android:textSize="15dp" />
</LinearLayout>
For each of your edittext make this:
<EditText
android:id="#+id/etEnterSpecificyear"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:hint="" >
</EditText>
And delete the TextView's that are in between the EditText's
Your issue is that you are using android:ems="10" in EditText properties. This one makes the minimum width of the EditText to be exact ten "M" characters. If this is your requirement I would suggest to use android:orientation="vertical" in the parent LinearLayout. So your final layout will look like:
<?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/tvSearchDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Enter Date to search..."
android:textSize="15dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/etEnterSpecificyear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="">
</EditText>
<EditText
android:id="#+id/etEnterSpecificMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="">
</EditText>
<EditText
android:id="#+id/etEnterSpecificDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="">
</EditText>
</LinearLayout>
<Button
android:id="#+id/btnSearchDate"
android:layout_width="85dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Submit"
/>
<TextView
android:id="#+id/tvSearchResultsDate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="30"
android:minLines="5"
android:scrollbars="vertical"
android:text=" Results..."
android:textSize="15dp"/>
</LinearLayout>
how do i align spinner to show equal in width in all screen? in my code spinner show different width in different screen what do i do? i have given fixed length
android:layout_marginRight="45dp"
android:layout_marginLeft="45dp"
in edittext and spinner but spinner show diffrent width in diffrent screen how do i fix this issue? i this is my image of screen http://imgur.com/RtWNgNI
and below is my full source code of screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical"
android:weightSum="6" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="55dp"
android:layout_weight="0.5"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:src="#drawable/agappbg" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="1" >
<EditText
android:id="#+id/txtMobileNo"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="left"
android:hint="#string/MobileNo"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="1" >
<EditText
android:id="#+id/txtPinNo"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="left"
android:hint="#string/PinNo"
android:inputType="textPassword"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:orientation="horizontal"
android:weightSum="1" >
<Spinner
android:id="#+id/lgnspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-17dp"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_marginTop="-15dp"
android:layout_weight="1"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:prompt="#string/network_prompt" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:orientation="horizontal"
android:weightSum="4" >
<Button
android:id="#+id/btnLogin"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight="1"
android:background="#drawable/curvedplanebutton_small"
android:text="Login"
android:textColor="#drawable/button_text_color" />
</LinearLayout>
It is not your fault, default background of Spinner has this kind of image (transparent padding around it). You can see yourself by setting android:background="#ffffff" on Spinner, doing this will remove padding from Spinner's sides and your problem will solve but you will loose Spinner arrow. I suggest you to create your own drawable for Spinner (because you are changing backgrounds of other View) otherwise default background is different for different OS versions and your implementation will seem broke.
Also you are using so many LinerLayouts for this simple layout. Consider this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical"
android:weightSum="100" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="30"
android:paddingBottom="10dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="70"
android:orientation="vertical"
android:padding="16dp" >
<EditText
android:id="#+id/txtMobileNo"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="4dp"
android:background="#ffffff"
android:gravity="center_vertical"
android:hint="MobileNo"
android:padding="4dp"
android:singleLine="true" />
<EditText
android:id="#+id/txtPinNo"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="4dp"
android:background="#ffffff"
android:gravity="center_vertical"
android:hint="Pin no"
android:inputType="textPassword"
android:padding="4dp"
android:singleLine="true" />
<Spinner
android:id="#+id/lgnspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:background="#ffffff" />
<Button
android:id="#+id/btnLogin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Login" />
</LinearLayout>
</LinearLayout>
Adjust your references again, in case you copy paste my code.
Actually you did code right. It just seem like its not same size with EditText box because you used default background in spinner.
If you changed its background color or image like
android:background="#android:color/darker_gray"
And you can change its background image
android:background="#drawable/spinnerDropDownBackground"
And make sure image is 9 path So that it will not starched in big screen
How to create 9 patch for spinner ?
you will find that you did code right.
And if you want to use default background you have to change your code
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
Hope this will help
I have 3 edit texts on a screen. On small screen devices before touching a edittext my screen looks like
And after touching first edittext(e.g. in front of name), keyboard popup comes, and it looks
i.e. now edittext Amount(which in front of TextView named Amount) is now in front of the user. But as I have touched(or clicked) first(Name) edittext, I want it in front of the user. But no matter which I select every time Amount is in front.
I have tried using requestFocus() and setSelect(true). Even has focus returns true, but nothing works.
So how to do that?
I have given scroll view to the tablelayout which contains these three edittexts and three text boxes in front of them.
my xml code is
<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:orientation="vertical" >
<LinearLayout
android:id="#+id/rl_upload_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:minHeight="50dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/selected_image_detail"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/rl_upload_top"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_weight="4"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:contentDescription="#string/empty" >
</ImageView>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center" >
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_table" />
<EditText
android:id="#+id/ed_img_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/text_box_background"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/name"
android:paddingLeft="5dip" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dip" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/amount_table" />
<EditText
android:id="#+id/ed_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/text_box_background"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/amount"
android:paddingLeft="5dip" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dip" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/desc_table" />
<EditText
android:id="#+id/ed_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/text_box_background"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/desc"
android:paddingLeft="5dip" />
</TableRow>
</TableLayout>
</ScrollView>
<LinearLayout
android:id="#+id/rl_upload_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center"
android:minHeight="70dp" >
<Button
android:id="#+id/button_update"
android:layout_width="150dp"
android:layout_height="40dp"
android:background="#drawable/btn_update" >
</Button>
</LinearLayout>
Add below line to manifest for related activity,
android:windowSoftInputMode="adjustPan"