i have a problem with my scrollview...
my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ScrollView android:id="#+id/scrollView1" android:layout_width="wrap_content" android:layout_height="match_parent">
<RelativeLayout [...]>
<TextView [...]></TextView>
<Spinner [...]></Spinner>
<Button [...]></Button>
<ImageButton [...]></ImageButton>
<TextView [...]></TextView>
<TableLayout [...]>
<TableRow [...]>
<TextView [...]></TextView>
<TextView [...]></TextView>
<TextView [...]></TextView>
</TableRow>
<TableRow [...]>
<AutoCompleteTextView [...]></AutoCompleteTextView>
<AutoCompleteTextView [...]></AutoCompleteTextView>
<Spinner [...]></Spinner>
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
When i try to scroll in my App it wont work... what did i do wrong?
i deleted the properties from the elements. if you need them to solve the problem i can add them.
i did it to get a better overview.
thanks,
prexx
Try adding the ScrollView as the parent. Swich place with LinearLayout.
And dont forget to add the following on your ScrollView instead of the LinearLayout:
xmlns:android="http://schemas.android.com/apk/res/android"
And layout_widht and layout_height of the ScrollView should be set to "fill_parent"
This is my code which uses ScrollView in a calendar I made, could help you:
<?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:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/dayView" android:text="Day" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
<Button android:id="#+id/weekView" android:text="Week" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
<Button android:text="Month" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false"/>
<Button android:id="#+id/eventsView" android:text="Events" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/prevMonth"
android:src="#drawable/calendar_left_arrow_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<Button
android:id="#+id/currentMonth"
android:layout_weight="0.6"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#drawable/calendar_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<ImageView
android:id="#+id/nextMonth"
android:src="#drawable/calendar_right_arrow_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="20dp" android:text="Week" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/monday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/tuesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/wednesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/thursday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/friday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/saturday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/sunday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ViewFlipper
android:id="#+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="#+id/weeks"
android:numColumns="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:scrollbars="none">
</GridView>
<GridView
android:id="#+id/calendar"
android:numColumns="7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none">
</GridView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="#+id/weeks2"
android:numColumns="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:scrollbars="none">
</GridView>
<GridView
android:id="#+id/calendar2"
android:numColumns="7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none">
</GridView>
</LinearLayout>
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/create_event"
android:text="Create event"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Try adding android:fillViewport="true" to your scrollView.
The height of your scrollView should probably be either match_parent or fill_parent aswell.
If the ScrollView content doesn't take up the whole space, it will behave as a normal layout, i.e. non-scrollable.
If you still need the ScrollView to fill the entire screen (but still not scroll since there is not enough content) you could do as Nicholas Magnussen mentioned and add android:fillViewport="true"
Please change to android:layout_width="wrap_content" android:layout_height="wrap_content"
to fill parent.
Thank you
Related
In this code I need align the buttons a Textview to the left, I try everythnin , with relative layout, gravity etcc....
I dont now why this align still togehter to the center in horizontal line, I need to the left side!
<?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="#color/dark_background"
android:orientation="vertical"
android:gravity="left" >
<ScrollView android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:gravity="left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dip"
>
<TextView
android:id="#+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/help_page_intro"
android:padding="2dip"
android:layout_weight="1"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="4dip"
android:layout_gravity="left"
>
<Button android:id="#+id/help_button1"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section1"
android:drawableTop="#drawable/help_image1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section1"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button android:id="#+id/help_button2"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section2"
android:drawableTop="#drawable/help_image2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section2"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentLeft="true">
<Button android:id="#+id/help_button3"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section3"
android:drawableTop="#drawable/help_image3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section3"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left" >
<Button android:id="#+id/help_button4"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section4"
android:drawableTop="#drawable/help_image4"/>
<TextView
android:layout_width="wrap_content"
android:gravity="left"
android:layout_height="wrap_content"
android:text="#string/help_text_section4"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
Sorry, not fully understanding. Did you want them lined up vertically? Then that would just be setting orientation to vertical in the linear layout. I looked at what this xml does right now. It appears to be button which is half the screen and textview with is the other half. Could you explain a little more what you want to see?
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<Button android:id="#+id/help_button1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:onClick="onClickHelp"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:id="#+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#color/black"
android:padding="2dip"
android:layout_weight="1"
/>
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
I have a layout as below
<LinearLayout>
<RelativeLayout>
</RelativeLayout>
<ScrollView>
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
this is to divide the screen into half showing graph at one half of the screen and the report at the other half which alone i wish to be scrollable.
UPDATE
Please find the xml as below
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#888888" />
<LinearLayout
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_marginBottom="10sp"
android:orientation="vertical">
<TextView
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor=""
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor=""
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#888888"
android:orientation="vertical" />
<LinearLayout
android:id=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
android:orientation="horizontal">
<RelativeLayout
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:id="#+id/course_status"
android:layout_alignParentLeft="true"
android:textColor="#000000"
android:textSize="14sp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:id=""
android:layout_marginTop="50dp" />
<edu.apollogrp.android.widget.ProgressCircle
android:id=""
android:layout_width="170dp"
android:layout_height="170dp"
android:indeterminateOnly="false"
android:layout_centerInParent="true"
android:progressDrawable=""
android:layout_marginTop="50dp"
/>
<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:id=""
android:layout_marginTop="50dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight=""
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:addStatesFromChildren="false"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#
android:textColor="#color/grades_green"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="#
android:textColor=""
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> </TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:layout_marginLeft="40dp" >
<TextView
android:id="#
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/grades_green"
android:textSize="12sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="9sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:background="#888888"
android:orientation="horizontal" />
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:fillViewport="false"
>
<LinearLayout
android:id="#
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
but the whole layout is scrollable now :(
Is there any way i can make only half the screen scrollable?
PS: android:fillViewport is set to false
UPDATE
I found out why the scroll is not working. it was because the scroll was inside a pull to refresh list view. :(
Looking for a work around for that now
Use layout_weight, here is sample code
<LinearLayout>
<RelativeLayout android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<ScrollView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
try to put the layout_weight attribute to divide the screen.
<LinearLayout>
<RelativeLayout android:layout_weight="1">
</RelativeLayout>
<ScrollView android:layout_weight="1">
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
you can try this:
<?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="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parentt"
android:layout_marginLeft="5dp"
android:background="#ffff"
android:layout_weight="1">
////// Your left side layout content /////////
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#ffff"
android:orientation="vertical"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
>
<TextView
android:id=""
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
The scroll view was not working because it was inside a list view that implements the pull to refresh.. Hence the layout changes dont effect.
Sorry everyone, thanks a bunch for the help.
i have a layout made in xml for an android app. The last textview it is not shown. why? what can i do? i try setting the linearlayout with height : fill_parent, wrap_content and match_parent:
this is the layout:
<?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" android:background="#drawable/sfondo">
<LinearLayout android:id="#+id/linearLayout2"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_height="fill_parent" android:weightSum="1"
android:layout_width="fill_parent" android:orientation="horizontal">
<ImageButton android:id="#+id/back1" android:src="#drawable/back"
android:background="#null" android:layout_marginTop="25dip"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageButton>
<ImageView android:layout_height="wrap_content" android:id="#+id/logoTC"
android:src="#drawable/trovachiavi_contatti" android:layout_width="wrap_content"
android:layout_marginTop="20dp">
</ImageView>
<ImageButton android:id="#+id/infoButton"
android:background="#null" android:layout_height="wrap_content"
android:layout_marginTop="10dip" android:src="#drawable/info_mini"
android:layout_width="wrap_content"></ImageButton>
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="fill_parent" android:id="#+id/layoutGif1"
android:orientation="vertical">
<spazio.digitale.com.GIFView
android:layout_gravity="center" android:layout_width="wrap_content"
android:layout_height="220dp" android:id="#+id/GIFMulti"
android:layout_marginLeft="40dp"></spazio.digitale.com.GIFView>
<TextView android:layout_height="wrap_content" android:id="#+id/testoAiuto"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content" android:gravity="center"
android:textColor="#android:color/black" android:layout_marginTop="-210dp"></TextView>
<ImageButton android:layout_gravity="center|bottom"
android:layout_width="wrap_content" android:layout_marginTop="25dp"
android:layout_height="wrap_content" android:background="#null"
android:id="#+id/avvia_cerca"></ImageButton>
<TextView android:layout_width="match_parent" android:id="#+id/testoRicercaMulti"
android:layout_height="wrap_content" android:textColor="#android:color/black"
android:textSize="14dp" android:gravity="center"
android:layout_gravity="center" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</TextView>
</LinearLayout>
It looks to me like your layout just isn't fitting. Wrap your views in a ScrollView, for example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/sfondo">
...
<ScrollView android:id="#+id/scroll" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="match_parent" android:id="#+id/testoRicercaMulti"
android:layout_height="wrap_content" android:textColor="#android:color/black"
android:textSize="14dp" android:gravity="center"
android:layout_gravity="center" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</TextView>
</ScrollView>
</LinearLayout>
Hope that helps!
your layout doesn't fit on your screen. wrap your main LinearLayout inside a ScrollView.
I have a layout problem, the idea is that the buttons and text dont show
<?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="#ffffff" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#5094c5"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Set the height and width in the xml layout file to what they should be when they are visible but initially, in code, get a reference to them and make them invisible. Then, when needed, you can make them visible (in code).
Maybe better try with RelativeLayout. This seems to be too nested and too much complicated than it suppose to be.
You can give setVisibility() property to button and textview in layout.
I finally managed to get my list to display properly (http://stackoverflow.com/questions/5662277/how-to-line-up-intger-output-in-custom-android-dialog).
Now I am trying to add a button below the list. What happens is that when the list is too big the button doesn't show.
The list is scrollable but that's it.
Also, the scrollbar covers some of the data.
This is the main XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="2dp"/>
</LinearLayout>
<ListView android:id="#+id/lvwScores" android:layout_below="#id/lloPlayerNames"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<Button android:id="#+id/btnOK "
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_below="#id/lvwScores" android:layout_weight="1"
android:text="OK" android:layout_centerHorizontal="true" />
</RelativeLayout>
This is the one for the rows:
<?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:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Score" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
I tried changing the main to a linear layout but that made it even worse! The list looked like it had been on a crash-diet and was super-thin.
Tried:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="2dp"/>
</LinearLayout>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="OK" android:layout_centerHorizontal="true"
layout_alignParentBottom="true"/>
<ListView android:id="#+id/lvwScores" android:layout_above="#id/btnOK" android:layout_below="#id/lloPlayerNames"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1"/>
</RelativeLayout>
and what I get is:
when I try:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">>
<LinearLayout android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="2dp"/>
</LinearLayout>
<ListView android:id="#+id/lvwScores"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1"/>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="OK" android:layout_centerHorizontal="true"
layout_alignParentBottom="true"/>
</LinearLayout>
I get:
Following is what I do on a couple of my apps with a ListView or a ScrollView, where I also have a fixed button or LinearLayout of buttons at the bottom. The "magic" is to set android:layout_weight="1" in the ListView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fastScrollEnabled="true" />
<TextView
android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Quotes!" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="My Button" />
</LinearLayout>
You should put the button before the list and then use the layout_above property on the list element to position it above the button. Also add layout_alignParentBottom="true" to your button.
Like so:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvwPlayer4Name" android:layout_weight="1" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="2dp"/>
</LinearLayout>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_below="#id/lvwScores" android:layout_weight="1"
android:text="OK" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
<ListView
android:id="#+id/lvwScores"
android:layout_below="#id/lloPlayerNames"
android:layout_above="#id/btnOK"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
Try adding a attribute android:below="#id/lvwScores" to the Button in main xml, this will place the Button below the ListView.
See this tutorial for more about RelativeLayout.