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.
Related
I have been trying to develop an android app that contain an activity which is scrollable
and inside the activity, I have 2 textView which I want them to be scrollable as well.
My problem is that
whenever I touch inside the textView the scrolls show up but the main activity part which is the linearLayout directly steel the focus and no longer the textView scroll
the way I have it now is setup for the textView to scroll in the xml file I have done that.
and if I keep raising my finger and put it back on the screen trying to scroll the textView I can move a little bit but as I said, the layout that contains the textView capture the focus and leave me unable to scroll the textView.
I hope I did explain my problem very well.
Please any suggestion to help.
let me explain how the app is built first
first part is: the main(first) activity is a tabHost
which I defined as scrollable
<?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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</ScrollView>
</TabHost>
where I am having problem with is this activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/light_gray_color"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/linearLayout3"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/black_color"
android:layout_gravity="center_horizontal"
android:text="#string/display_label"
android:id="#+id/display_label">
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.83"
android:baselineAligned="false"
android:orientation="horizontal" >
<ScrollView
android:id="#+id/english_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_english_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
<ScrollView
android:id="#+id/translation_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_translation_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
</LinearLayout>
</LinearLayout>
I guess you should cut <ScrollView> out of the first xml
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</TabHost>
My understanding is that you have a vertically scrolling activity, which contains two vertically scrolling text views? If so, you can't do it. Its not just a poor design choice, its literally impossible to tell which view the user intends to scroll when they make swipe motion. You can have horizontal scrolling inside a vertically scrolling view, or vice versa. You can't have horizontal scrolling inside horizontal scrolling or vertical scrolling inside vertical scrolling.
I believe this is mentioned in the listview talk in the 2010 google io conference: http://www.youtube.com/watch?v=wDBM6wVEO70
I want to make my TextView vertically scrollable. I have read "Making TextView Scrollable in Android" but since I don't know the size of the screen of the final device, I can't know which value should be set for maximum lines.
Is there any other way, so it gets the scrolling for any screen size?
My XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_weight="1.0">
<TextView
android:id="#+id/consola"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</ScrollView>
<EditText
android:id="#+id/comando"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0">
<Button
android:text="Conectar"
android:id="#+id/boton_conectar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Enviar"
android:id="#+id/boton_enviar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
Look, here the structure of my XML layout with scroll:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:visibility="visible">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
.....
//your sub-widgets
.....
</LinearLayout>
</ScrollView>
As for me, works fine.
If you do not know number of lines (moreover, it could vary if soft input method are shown or not), you should use RelativeLayout to place you widget like TextView. And then connect both (it's critical, not one but both) top and bottom edges of it to parent withandroid:layout_alignParentTop and android:layout_alignParentBottom attibutes, or neighbors with android:layout_above and android:layout_below attributes.
After both sides are connected to other widgets, android will recalculate size of TextView and scroller properly, even if you change orientation or show/hide soft keyboard.
ScrollView is only allowed to have one sub widget.
You should put the linearlayout inside of the scroll view. and set the textview inside of the linear layout.
Put the TextView inside ScrollView with height = MATCH_PARENT
try:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_weight="1.0">
<TextView
android:id="#+id/consola"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</ScrollView>
<EditText
android:id="#+id/comando"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:text="Conectar"
android:id="#+id/boton_conectar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Enviar"
android:id="#+id/boton_enviar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
My layout was perfect until I decided to add a scrollview.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="#+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:id="#+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="#+id/linearLayout1">
<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/tableLayout1"/>
</LinearLayout>
</ScrollView>
<Button android:layout_width="match_parent" android:id="#+id/button1" android:text="Start" android:layout_height="50dip" android:onClick="getOutput"></Button>
</TableLayout>
I would like the button to stay at the bottom of the screen, I would actually like the scrollview to take up the entire screen. With just the inner table layout it works fine. In the Graphical Layout preview it looks how I want it, but not when I run it.
I would like the scrollview to take up the whole screen except the button, which I'd like to be at the bottom.
you could use RelativeLayout or LinearLayout as Root view. Giving Button more weight. That way ScrollView won't take up the whole thing.
this should work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:id="#+id/linearLayout1">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tableLayout1"/>
</LinearLayout>
</ScrollView>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Bottom Button"/>
</LinearLayout>
Try setting ScrollView fillViewport attribute to true.
I have a layout that is three linear layouts. The top has some icons and the middle has a tabhost. Each tabhost has a list inside it. The bottom linearlayout has two buttons that should stay at the bottom on the screen at all times. The problem is when a list in the tabhost gets too long, it displays over the buttons. I tried to find some way to get the buttons to bedisplayed over the list but have failed so far. Any help would be appreciated. :-) Thanks!
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="395dp"
android:background="#000000">
<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="wrap_content"
android:padding="5dp"
/>
</LinearLayout>
</TabHost>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill"
android:layout_margin="0dp"
android:padding="0dp"
>
<Button
android:id="#+id/btnGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Ptt"
android:layout_gravity="bottom"
android:layout_weight="2"
android:hapticFeedbackEnabled="true"/>
<Button
android:id="#+id/btnMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu"
android:layout_gravity="bottom"
android:layout_weight="2"
android:hapticFeedbackEnabled="true"/>
</LinearLayout>
I generally put my LinearLayouts inside of a ScrollView to solve this situation. (The buttons stay outside) It allows your buttons to stay in the correct location at all times and the user scroll the rest of the view.
ScrollView Docs
I am trying to assign relative widths to columns in a ListView that is in a TabHost, using layout_weight as suggested here:
<?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">
<TableLayout
android:id="#+id/triplist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="4px">
<TableRow>
<ListView android:id="#+id/triplistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow>
<Button android:id="#+id/newtripbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Trip"/>
</TableRow>
[other tabs ...]
My row definition has 4 columns that I would like to size as follows:
<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="1.0"
android:padding="4px">
<TextView android:id="#+id/rowtripdate"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="date"/>
<TextView android:id="#+id/rowodostart"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/rowodoend"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/rowcomment"
android:layout_weight=".4"
android:layout_width="0dip"
android:layout_height="wrap_content">
Unfortunately, it seems to want to fit all the columns into the space that the button occupies, as opposed to the width of the screen. Or maybe there is another constraint that I do not understand. I'd appreciate your help.
(source: heeroz.com)
I think I forgot this property for the TableLayout element:
android:stretchColumns="0"
It appears to be working now.
I don't see anything obviously wrong in what you are showing there. To get a better picture of what is going on, you might try out the heirarchy viewer. It comes with the SDK. It will visualize for you how much space each of the "hidden" layers is taking, so you can figure out which one decided to only be that big.