Button to add a custom layout to android application - java

I have a small timesheet application of which I have added a screenshot because it is easier to show you than try to explain it all!
Hopefully from the picture you can see there needs to be a job number for the different sites where a worker will be and they can fill out their hours relative to each job number for the time spent on that job.So here is my problem I dont know how many job numbers they will have per week so here I just added in three but it may be more or less,could I have an "add job" button which could add one of the job views underneath each time it is pressed?
Below is the xml code for the section I would like to add each time the button is pressed
<LinearLayout
android:id="#+id/MainLayoutThree"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > //start of 1st job layout
<LinearLayout
android:id="#+id/LayoutTwoA"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/beige"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/jobNo" >
</TextView>
<EditText
android:id="#+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1">
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ordHours" >
</TextView>
<EditText
android:id="#+id/editText4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1">
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/LayoutThree"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/beige"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/overTimeHours" />
</LinearLayout>
<LinearLayout
android:id="#+id/LayoutFour"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/beige"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x1.25" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x1.50" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x2" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1">
</EditText>
</LinearLayout>

You can inflate the View in button's onClick as shown below:
addButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater inflater = LayoutInflater
.from(getApplicationContext());
View view = inflater.inflate(R.layout.job_row_layout, null);
containerLayout.addView(view);
}
});
Hope this helps.

Related

Android Scrollview doesn't wrap child

Here's the Layout xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:scrollbars = "vertical">
<LinearLayout
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="factory.Settings"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblShopID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ShopId"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtShopID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblShopname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/lblShopID"
android:layout_marginTop="36dp"
android:text="#string/ShopName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinShopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/lblShopname"
android:layout_toRightOf="#+id/lblShopname" />
</LinearLayout>
<Button
android:id="#+id/btnSaveChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/spinShopName"
android:layout_marginTop="22dp"
android:onClick="saveData"
android:text="Save Changes" />
<TextView
android:id="#+id/txtChangePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="#string/ChangePassword"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="30px" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30px">
<TextView
android:id="#+id/lblOldPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/OldPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtOldPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblNewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NewPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtNewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblRetypePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/RetypePassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtRetypePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="#+id/btnChangePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changePassword"
android:text="Change Password" />
<ListView
android:id="#+id/lstUsers"
android:layout_width="340dp"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
And Here's the expecting output:
The expected output is : I have some items in lstUsers and there wouldn't be enough space for displaying all the users, so I would like to add a scrollview to the Layout to let users scroll down.
But the problem is: the scrollview doesn't wrap any controls at all, the outcome is:
As you can see, the scrollview is unable to wrap the lstUser
Is there anything wrong with the layout file?
I don't think you are allowed to put a listview in a scrollview. Listview implements its own scroller so it doesn't like being in a scrollview. Take a look at this link
How can I put a ListView into a ScrollView without it collapsing?
Scrollview and Listview do not work well with each other.
What I would suggest u is to make 'lstUsers' Listview the main content of the layout file.
Create a separate layout file with the views that are above the listview.
Then inflate this layout file and add it as a header view to the listview.

how to add a fragment multiple times inside a parent layout?

I want to add a particular layout till 14 views. So that layout can be add till 14 times not after that. I have a next destination layout after clicking on the next destination this layout should get added.
So for that I have choose fragment. Now I can add the fragment onClick of the next destination layout. But nothing happens when I again click on next destination layout. How can I add this till 14 times??
And I have a remove destination layout. OnClick of this the layout should swipe to right and should get removed by animation. How can I achieve this??
I want to do like this :
GoBoxActivity
nextDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//addedDestination.setVisibility(View.VISIBLE);
//removeDestination.setVisibility(View.VISIBLE);
fragment = new NextDestinationFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
}
});
Fragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:id="#+id/LinearAddedDestination">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
Can anyone help please..?
You need to implement a FragmentAdapter in order to manage multiple fragments. Then you have to inflate those fragments in some sort of ListView or ViewPager. Have a look at this or that tutorial.
Using an OnTouchListener you are able to implement the swipe gestures to remove your fragments from List/Pager.
Hope this helps. Cheers
You should use fragmentManager.beginTransaction().add(R.id.container, fragment) to add new Fragment and use remove() to remove it.
For animation,you can use fragmentManager.beginTransaction(). setTransition() to set the animation that Android offers when fragment is added,removed.If you want to implement custom animation,you can use fragmentTransaction.setCustomAnimations(enterAnimation,exitAnimation),and write the two animation in your XML file.
Hope this can help you.

How to make a textview to wrap its content but also alignBottom to another textview?

I have this textview, tv1, and it contains 4 lines of words. I have this second textview, tv2, and it will vary from 1 line of text to 6 lines of text. How can I make tv1 always show 4 lines of text, but expand when tv2's text goes to 6 lines of text?
Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/labeltvItem1Pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/tvMagRes"
android:layout_below="#+id/labeltvSpeed"
android:layout_alignBottom="#+id/tvItem1Pass"
android:layout_alignTop="#id/tvItem1Pass"
android:text="Passive from first item: "
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvItem1Pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="460dp"
android:layout_toRightOf="#+id/tvMagRes"
android:gravity="center_horizontal"
android:text="Nothing"
android:textSize="12sp" />
</RelativeLayout>
</ScrollView>
Beautiful paint image:
Feel free to rephrase this question if its confusing
I've tried to change around the code with no success. Any more help?
Try this.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/labeltvItem1Pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="Passive from first item: "
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvItem1Pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Nothing"
android:textSize="12sp" />
</RelativeLayout>
then try this.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weight_sum="10"
android:gravity="bottom"
>
<TextView
android:id="#+id/labeltvItem1Pass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Passive from first item: "
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvItem1Pass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Nothing"
android:textSize="12sp" />
</LinearLayout>

Centering my linear layout in android

I'm trying to achieve this positioning:
Where I have two rows of EditText and TextView next to each other.
The version textview is anchored to the bottom of the screen, but takes up the entire width and the text is centered.
My current layout file is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center_vertical"
tools:context="com.example.mp.MainActivity$PlaceholderFragment" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext1"
android:layout_width="250dip"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext2"
android:layout_width="250dip"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:gravity="bottom">
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.0"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</RelativeLayout>
</LinearLayout>
But the two rows of EditText and TextView are positioned past the middle of the screen and the Version textview is immediately below the two rows of EditText and TextView instead of anchored at the bottom.
I would recommend using a RelativeLayout for the root layout and use the property android:layout_alignParentBottom="true" for the "version". Then wrap the other Views in a LinearLayout. Something like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="#+id/edittext1"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/edittext2"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview2"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.0"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I haven't had a chance to really test it but this should get you pretty close. I wrapped the two sets of Views in the center in a LinearLayout then gave each their own LinearLayout so they can make use of weight (which you can adjust to your needs). The parent LinearLayout is centered vertical so that those 4 Views will be centered the way I believe you want.
<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"
android:gravity="center">//hope this will work for you
<LinearLayout
android:id="#+id/alltextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"`enter code here`
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="EditText" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
</LinearLayout>
<LinearLayout
android:id="#+id/alltextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="EditText" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
</LinearLayout>

how to add three button at bottom layout

i want to add three buttons at the bottom like this image
below listview which is equal size my code is below help me how do i add this three button in my layout this is my 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="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/border" >
<ImageView
android:id="#+id/test_button_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingTop="5dp"
android:src="#drawable/icon" >
</ImageView>
<TextView
android:id="#+id/test_button_text2"
android:layout_width="wrap_content"
android:paddingTop="10dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/test_button_image"
android:paddingLeft="10dp"
android:layout_toRightOf="#+id/test_button_image"
android:text="San Diego Unified"
android:textColor="#000000"
android:textSize="25sp" >
</TextView>
<TextView
android:id="#+id/test_button_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:layout_alignLeft="#+id/test_button_text2"
android:layout_below="#+id/test_button_text2"
android:paddingBottom="10dp"
android:text="SCHOOL DISTRICT"
android:textColor="#000000" >
</TextView>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/border1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="HEALTHY BODIES HEALTHY MINDS "
android:textColor="#000000"
android:textStyle="bold"
android:textSize="11sp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:paddingRight="5dp"
android:padding="5dp"
android:background = "#null"
android:src="#drawable/facebook" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background = "#null"
android:padding="5dp"
android:src="#drawable/twitter"
android:text="Button Text" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="10dp"
android:background="#00FFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Search School By Name"
android:layout_centerVertical="true" >
</EditText>
<ImageView
android:id="#+id/imageView1"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignRight="#+id/editText1"
android:src="#drawable/title_search" />
</RelativeLayout>
<TextView
android:id="#+id/txtCaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingBottom="3dp"
android:paddingLeft="10dp"
android:paddingTop="3dp"
android:text="SELECT A SCHOOL TO VIEW LUNCH OR BREAKFAST MENUS"
android:textColor="#000000"
android:textSize="10sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/lytContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/txtCopyright"
android:layout_marginTop="15dp"
android:background="#drawable/border2"
android:layout_below="#+id/lytTitlebar"
android:orientation="vertical" >
<ListView
android:id="#+id/listMainMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="#drawable/listview_selector"
android:dividerHeight="1dip"
android:fadeScrollbars="true" />
</LinearLayout>
</LinearLayout>
Take one linear layout below listview and give its orientation as horizontal and then add three textview one after the other with a seperator(i.e using View) and then put a click event on each and every textview and use it and put that linear layout gravity = bottom.
Here is the simple solution...
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/border" >
<Button 1>
<Button 2>-center horizontal and center vertical
<Button 3>-align parent right- true
Add what further properties you want to add in button.

Categories