Layouts in Android

I have two questions.

  1. How can I get the spinner in the figure below closer to the text?

I use the following xml layout

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="4">   

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Check by" 
        android:layout_weight="1"
        android:textSize="20dp"/>

    <Spinner
        android:id="@+id/CheckBy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="20dp" 
        android:enabled="false"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Outcome"
        android:layout_weight="1"
        android:textSize="20dp"/>

    <Spinner
        android:id="@+id/Outcome"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="20dp" 
        android:enabled="false"/>

</LinearLayout>
  1. How can I change the text of the enter button, as in the below figure, and assign an action to be performed when it is clicked?

Answers


1) For the layout design use below code -

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Check by" 
        android:textSize="20dp"


        />

    <Spinner
        android:id="@+id/CheckBy"
        android:layout_marginLeft="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp" 
        android:enabled="false"

       />

    <TextView
        android:layout_width="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_height="wrap_content"
        android:text="Outcome"
        android:textSize="20dp" 

         />

    <Spinner
        android:id="@+id/Outcome"
        android:layout_marginLeft="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp" 
        android:enabled="false" 

       />


</LinearLayout>

Simply remove the weightsum and give the wrap_content as width.


You can't change the enter button's text. It's in the default keyboard. You have to write yourself one, if you want to have custom button text.

And you can't "assign" an action to the button, but you can implement your type of EditText (assuming that the text fields are of type EditText) which overrides the public boolean onKeyDown (int keyCode, KeyEvent event) and/or public boolean onKeyUp (int keyCode, KeyEvent event) methods (or any other you find suitable for your goal). Check the EditText's documentation for onKey... methods. In the method you find more suitable you can implement the desired functionality (the action).


I have found your answer of the 1st Question by using Linear Layout.I suppose it will help you.The Code is as follows:-

    <?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="wrap_content"
        android:orientation="horizontal" >
    <TextView
        android:id="@+id/lblCheckBy"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:gravity="right"
        android:text="Check by" />

    <Spinner
        android:id="@+id/spnCheckBy"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" />

    <TextView
        android:id="@+id/lblOutcome"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:gravity="right"
        android:text="Outcome" />

    <Spinner
        android:id="@+id/Outcome"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" />

</LinearLayout>

And for your 2nd Answer this is the link which will lead you to the correct solution.the link is:-Imp Link


Need Your Help

Is the Windows 7 Task Bar the new Notification Area?

windows-7 taskbar user-experience notification-area

I've seen a few Windows 7 applications popping up around the web that take advantage of the new task bar functionality. However, some of these applications are treating the task bar like the notifi...

How to write to an existing XML file using java

java xml

I've got an xml file looked like this. employees.xml