I have made one Layout in which I want to set the another layout from the existing xml file. Is this possible?
See below code:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
Now I want to set the Layout in the frameLayout`
how it this possible?
Thanks.
Just create another activity with your second layout and then start the second activity with startActivity().
You didn't provide any code, but if you have 2 layouts in xml and the first one should include the second one, use the include-tag.
Related
How to delete 2 point in bottom of tabhost
Please see below image to get more detail.
Thanks so much.
This is XML, I'm using default tabhost and i don't know why they appear
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginBottom="50dp">
<TabHost android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:layout_marginLeft="-4dp"
android:layout_marginRight="-4dp"
android:layout_marginTop="37dp"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
style="#color/white"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</FrameLayout>
You're going to need to post the XML/Code you used to create this.
For the app I'm working on I'd like to have 3 tabs with different elements in them.
I tried searching for a way to accomplish this but I can't seem to find an example of what I need.
Basicly I want this:
Tab 1, contains 4 buttons and a textview
Tab 2, contains an scrollable imageview
Tab 3, contains an webview
I would like to solve this problem without the use of activity's because all 3 tabs need to access the same data.
Currently I use this xml as layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/photoLayout">
<Button
android:text="#string/photoButton"
android:layout_column="0"
android:id="#+id/photoButton"
android:textSize="10dp" />
<Button
android:text="#string/locateButton"
android:layout_column="1"
android:id="#+id/locateButton"
android:textSize="10dp" />
<Button
android:text="#string/cropButton"
android:layout_column="2"
android:id="#+id/cropButton"
android:textSize="10dp" />
<Button
android:text="reset"
android:layout_column="3"
android:id="#+id/resetButton"
android:textSize="10dp" />
<ScrollView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="370dp"
android:id="#+id/scrollView1"
android:fillViewport="true">
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/textView1" />
</ScrollView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webviewLayout">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webView1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageLayout">
<ScrollView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="412dp"
android:id="#+id/scrollView2"
android:fillViewport="true">
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_column="0"
android:id="#+id/imageView1"
android:layout_height="411.6dp"
android:layout_width="316.7dp"
android:scaleType="centerInside" />
</ScrollView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
The problem with this is that I get a runtime exception saying:
Java.Lang.RuntimeException: Binary XML file line #1: You must supply a layout_width attribute.
Any help to solve this issue will be appreciated!
To answer the exception thrown, you need to specify layout_width and layout_height in every single elements you declared, which in your case, you did not specify any on those buttons.
But to express my curiosity, I believe you should anyhow make it in separate activities and separate layouts, "same data" can always be passed around using some extras I believe.
I have this layout file in my android application:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<LinearLayout
android:id="#+id/layoutSearch"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Search here" />
<EditText
android:id="#+id/editSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
</TabHost>
My problem is that LinearLayout android:id="#+id/layoutSearch" shows only one of the elements it contains (the text view, in the code above) If I remove the textview, it shows the EditText.
How do I make it display both (and more) elements?
There's a lot of excess layout there, but it looks like the real issue is that layoutSearch is a vertical LinearLayout with two children, but the first child's height is set to fill_parent, so you naturally never see the second one. Try setting its height to 0px but giving it a layout_weight of 1, and it should expand to take all the available space not taken by the EditText below it.
I'm completely new to java and .xml programing, and thanks to stack overflow and many other sites, I've been able to get a basic app started. The problem I'm having is this: I started with a tabbed layout with 4 tabs, and simple textviews with 3-4 pages of text in each tab. When I ran this on an emulator, I found the text wasn't scrolling, so after researching for a while, I figured that I needed a ScrollView in order to see all the text. I've now added the ScrollView, but only the first tab is scrolling. I've been looking all over for an answer, and can't seem to find one. I'm just hoping someone can look at my code, and perhaps see where I went wrong.
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:text="3-4 pages of text here"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lineSpacingExtra= "5sp"
android:background="#color/backgroundColor"
android:textColor="#color/textColor"/>
</ScrollView>
<ScrollView
android:id="#+id/ScrollView02"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview2"
android:text="3-4 pages of text here"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lineSpacingExtra= "5sp"
android:background="#color/backgroundColor"
android:textColor="#color/textColor"/>
</ScrollView>
<ScrollView
android:id="#+id/ScrollView03"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lineSpacingExtra= "5sp"
android:text="more text in here"
android:background="#color/backgroundColor"
android:textColor="#color/textColor"/>
</ScrollView>
<ScrollView
android:id="#+id/ScrollView04"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lineSpacingExtra= "5sp"
android:text="even more text here"
android:background="#color/backgroundColor"
android:textColor="#color/textColor"/>
</ScrollView>
/>
</FrameLayout>
</LinearLayout>
To make your TextView scrollable, you have to add the following code:
yourTextView.setMovementMethod(new ScrollingMovementMethod())
Please use the above code and let me know how it goes.
I been following the Tab example provided by Google. I am trying to use the XML layout provided to setup a tab layout.
I use this XML layout # http://developer.android.com/guide/tutorials/views/hello-tabwidget.html
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
When ever I switch the Layout tab in the Eclipse layout designer I get a NullPointerException: null error inside my Eclipse.
This happens also when I try to drag and drop a TabHost, and then a TabWidget into an empty layout file.
What am I doing wrong ? this seems pretty simple.
Found it has been recorded as an issue already
http://code.google.com/p/android/issues/detail?id=2021
Thanks anyway