I am trying to implement something like an action bar in android 2.2 .
This is my main.xml
<?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"
>
<include
android:id="#+id/header"
layout="#layout/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/dark_button"
>
<Button
android:id="#+id/brand_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/brand_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
/>
<Button
android:id="#+id/car_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/car_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<Button
android:id="#+id/model_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/model_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<Button
android:id="#+id/location_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/location_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<Button
android:id="#+id/submit"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/submit_label"
android:textColor="#color/white"
android:layout_marginTop="10dip"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<ProgressBar
android:id="#+id/mainProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
And this is my header.xml
<?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="match_parent"
android:orientation="horizontal"
>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo_toyota"
android:layout_weight="1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
I am getting the o/p as
I am wondering what is wrong with the code. I am new to android development. Any help is highly appreciated.
Thanks in advance
Aman Gautam
It is showed in horizontal orientation because it is set by default
In root layout of main.xml
just put android:orientation="vertical"
Instead of rolling out your own code, I highly recommend this open source project, (https://github.com/johannilsson/android-actionbar), I have used it in my own projects and it has worked quite well for me.
Related
When i preview with android emulator, the layout preview is ok. But when I install the app in my mobile the views overlaps. It may be because of lack of space in the mobile screen but I have no idea. Please help me out. And also help me with making this app to work with all screen sizes. Thanks in advance.
First image is emulator preview 2nd is mobile preview
Here is the xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
android:background="#drawable/newbackground"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
app:srcCompat="#drawable/dicee_logo" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/dice1" />
<ImageView
android:id="#+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/dice2" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:background="#color/colorPrimary"
android:text="#string/button_text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/roll_button"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/roll_button"
android:layout_marginBottom="25dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
</RelativeLayout>
</LinearLayout>
This will keep the 2 textview to bottom and will expand in whatever view you use
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="#drawable/ic_word" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_word" />
<ImageView
android:id="#+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_pdf" />
</LinearLayout>
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:text="text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
</LinearLayout>
Try the below modified code. Since you want the buttons below each other. You cannot place one on right of other, so remove the alignRight.
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
**android:layout_marginTop="21dp"**
android:background="#color/colorPrimary"
android:text="#string/button_text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/roll_button"
android:layout_alignParentBottom="true"
**android:layout_alignRight="#+id/roll_button"**
android:layout_marginBottom="25dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
My EditText element is displaying well in popup window but its not allowing to enter values,I cant type anything inside that edittext element.
here i have attached xml code and screenshot.if you want my main activity class java code too let me know i can add it here.
xml code :
`<?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:orientation="vertical"
android:background="#android:color/background_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="#android:color/darker_gray">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:id="#+id/texttitle1"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#891800"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appoinment" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<EditText
android:id="#+id/Easy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
/>
<Button
android:id="#+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="openNewActivity"
android:text="Save" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to Menu" />
</LinearLayout>
</LinearLayout>
</LinearLayout>`
take the input type text noSuggestions and replace it with text
Find the solution:
1.In Manifest file please write windowSoftInputMode :
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden" />
Please put these lines in main LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
3.Please check the document
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Try with below XML :
<?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="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="#android:color/darker_gray"
android:orientation="vertical"
android:padding="20dp">
>
<TextView
android:id="#+id/texttitle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appoinment"
android:textColor="#891800"
android:textSize="25dp"
android:textStyle="bold" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<EditText
android:id="#+id/Easy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions" />
<Button
android:id="#+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="openNewActivity"
android:text="Save" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to Menu" />
</LinearLayout>
</LinearLayout>
In my case, i had accidentally put android:descendantFocusability="blocksDescendants" to the parent layout,which blocks widgets inside this layout focusing. That is why, it was not working :)
If you have this line, please remove and it will work just fine
I'm Learner and designing an interface but there is little problem can some one help me out, attaching screen shot original and my design and also code.
I'm unable to adjust the button position in layout, and also if some one have links or stuff related beginners then also share
thanks.
Here is my XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_home__screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.sofagold.mrdeveloper.sofagold.Home_Screen"
android:background="#android:color/black">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.8">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/home_header"
android:layout_weight="1.3">
<Button
android:layout_width="62dp"
android:layout_height="wrap_content"
android:id="#+id/button3"
android:background="#drawable/home_home"
android:layout_gravity="start"
android:padding="5dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/home_small_logo"
android:id="#+id/imageView"
android:adjustViewBounds="true"
android:baselineAlignBottom="false"
android:layout_gravity="center"
android:layout_weight="5000" />
<Button
android:layout_width="59dp"
android:layout_height="wrap_content"
android:id="#+id/button8"
android:background="#drawable/home_back"
android:layout_gravity="start"
android:padding="5dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.2">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button24"
android:layout_toEndOf="#+id/button25"
android:layout_marginStart="64dp"
android:layout_marginTop="8dp"
android:id="#+id/button22"
android:layout_wieght="5"
android:background="#drawable/home_btn_bg" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/button22"
android:layout_marginBottom="48dp"
android:id="#+id/button24"
android:button_size="5dp"
android:background="#drawable/home_btn_bg" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button24"
android:id="#+id/button25"
android:button_size="5dp"
android:background="#drawable/home_btn_bg" />
RelativeLayout(end of)
</LinearLayout>
</LinearLayout>
I am working with android and I need to make an XML design in which I need to have three buttons at the bottom of my screen horizontally always. Just like facebook application in android, they have three buttons at the bottom of the screen (Status, Photo, Check In) - similarly I need to have three buttons as well always in my application.
What will be the design for this kind of layout?
I tried with the below XML design but it doesn't work somehow and they all are coming vertical -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/cow"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="ButtonA" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="ButtonB" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="ButtonC" />
</LinearLayout>
</LinearLayout>
I just need to show three buttons at the bottom of the screen horizontally just like facebook shows always side by side (touching each other). Is this possible to do?
Button names can be - ButtonA, ButtonB and ButtonC
Use below layout, i think its help you
<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:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center"
android:text="cow"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonA" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonB" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonC" />
</LinearLayout>
I don't know how you'll need to eventually adjust this, so I've left it pretty generic:
<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:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="2" />
</LinearLayout>
</LinearLayout>
Maybe you could use a layout with a Header-Footer-Content structure like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Header aligned to top -->
<RelativeLayout
android:id="#+id/header"
android:layout_alignParentTop="true"
...>
</RelativeLayout>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="#+id/footer"
android:layout_alignParentBottom="true"
...>
<!-- put your layout and buttons here -->
</RelativeLayout>
<!-- Content below header and above footer -->
<RelativeLayout
android:id="#+id/content"
android:layout_above="#id/footer"
android:layout_below="#id/header"
...>
</RelativeLayout>
You can remove pieces at your will.
Alright.. To start off, I'm new with Eclipse, new with Android Development, Java..
I have to make a VoIP Application, I set up some tabs (Yes the text is messed up) :
And here's my XML Code.
<?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" >
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="horizontal"
android:id="#+id/Recents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Recents">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/Keypad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Keypad" >
<Button
android:id="#+id/bNumber1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="#+id/bNumber2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="#+id/bNumber3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:id="#+id/bNumber4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="#+id/bNumber5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="#+id/bNumber6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:id="#+id/bNumber7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
<Button
android:id="#+id/bNumber8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="#+id/bNumber9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
<Button
android:id="#+id/bNumber0"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />
<Button
android:id="#+id/bCall"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Call" />
<Button
android:id="#+id/bSMS"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SMS" />
<Button
android:id="#+id/bClear"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C" />
<TextView
android:id="#+id/etNumberField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
>
</TextView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/Sms"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="SMS">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/Ratings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Ratings">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/Account"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Account">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Now, My problem is that I'll have to position all the "Number"-Buttons (1,2,3,4 etc..) and make them look like a real key-pad.
My problem is, I can't really "See" on the graphical layout how it's getting positioned.
I Can't code the buttons out of memory either, since I'm still new to it.
Is there anyone that could help me with the code, formatting them to a key-pad like format?
Or even give me a solution on how I could SEE the positioning as I'm coding it?
Thanks in Advance,
Paramone!
Alright, After some research I've figured it out.
If anyone was wondering how to change the Tab-View as they're coding, and be able to see how it looks like..-
Simply create An .XML file, and design it as you want the tab to look like.
Before this solution, I had to Edit my tab-views looking at this:
Later, you need to put in <include layout="#layout/recents" /> ("recents" is the .XML Layouts name.) in your Linear layout.
Mine looks like this:
<LinearLayout
android:id="#+id/Keypad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:text="Keypad">
<include layout="#layout/keypad" />
//"keypad" is the name of the .xml file.
</LinearLayout>
And That's how you "Change" the view.
Also, Since I'm new to Android Developing, I wanted to know how I could format my so they'd look like a legit Key-pad.
Thanks to the include code, I could actually SEE the tab as I was coding and designing it.
Screenshots:
What I did:
- Put all the buttons in Sets of 3.
So 1 LinearLayout would cover Buttons 1, 2 and 3.
The other one would cover 4,5 and 6 (And so forth)
- Put Weights on the LinearLayouts
This helped me "Push" them to the bottom.
I know that it's probably not the correct or safest way to do it, but as long as it works, I'm happy with it.
The XML Code:
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:paddingTop="10dp" >
<TextView
android:id="#+id/etNumberField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:ems="100"
android:singleLine="true"
android:textSize="23dp" />
<Button
android:id="#+id/bContact"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="10dp"
android:text="Contact" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="1dp">
<Button
android:id="#+id/bNumber1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="1"
android:padding="10dp" />
<Button
android:id="#+id/bNumber2"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2"
android:padding="10dp"/>
<Button
android:id="#+id/bNumber3"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="3"
android:padding="10dp" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="1dp">
<Button
android:id="#+id/bNumber4"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="#+id/bNumber5"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="#+id/bNumber6"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="6" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="1dp">
<Button
android:id="#+id/bNumber7"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="7" />
<Button
android:id="#+id/bNumber8"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="#+id/bNumber9"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="9" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="1dp">
<Button
android:id="#+id/bNumberStar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*" />
<Button
android:id="#+id/bNumber0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<Button
android:id="#+id/bNumberHash"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="1dp">
<Button
android:id="#+id/bSMS"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="SMS" />
<Button
android:id="#+id/bCall"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Call"
android:textColor="#00FF00"
/>
<Button
android:id="#+id/bClear"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="C"
/>
</LinearLayout>
</LinearLayout>
If you have any questions regarding this solution, or how I could possibly help you, feel free to post a comment below!