EDITED to improve specifics:
Hi, my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="10dp"
tools:context="${packageName}.${activityClass}" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="Select Character"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="#+id/textView1"
android:orientation="vertical"
android:paddingTop="10dp" >
<TextView
android:id="#+id/SelectedCharacterName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="#+id/TraitName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trait 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
etc...
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
android:fillViewport="false"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/Character1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4a4a4a"
android:clickable="true"
android:gravity="center"
android:text="Character 1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
etc...
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/buttonConfirmCharacter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="#string/button_Confirm" />
</LinearLayout>
I am looking to make the scrollview fit the remaining space between the other elements however with this setup the scrollview doesn't seem to render at all. These settings are the result of looking for solutions and implementing weight.
An answer without java code would be preferential.
Thanks.
Here, this would works just fine
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text1" />
<TextView
android:id="#+id/SelectedCharacterName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/TraitName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trait 1" />
etc...
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/Character1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:text="Character 1" />
etc...
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/buttonConfirmCharacter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/button_Confirm" /></LinearLayout>
Related
I got trouble with android layout in xamarin. How to fill space without overlapping the layout in android xml?
This layout confusing me. Because it's not like php or xaml. I want to make the layout view like this:
I'm using nexus 6 in design windows. When I ran the debug in emulator the view become like this:
The layout overlapping. I wonder how to fill blank space in android layout size so it can fit in my device (dynamically)?
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/main_content"
android:gravity="fill_horizontal|bottom">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="610.3dp"
android:layout_weight="1"
android:gravity="center|bottom">
<TextView
android:text="Location Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView9"
android:layout_marginTop="10dp"
android:gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="199.3dp"
android:id="#+id/linearLayout1"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout2">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout3"
android:layout_marginTop="5dp">
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView4"
android:width="100dp"
android:gravity="center|left|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView5"
android:gravity="center|top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailAddress" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/linearLayout4"
android:layout_marginTop="5dp"
android:gravity="top">
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView6"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView7"
android:gravity="center|top" />
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailDescription" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="Registered User"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_marginTop="10dp"
android:gravity="center" />
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/recyclerViewLocationUser"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressBarLocationDetail"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="50dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ff03a9f4"
android:layout_gravity="right"
android:gravity="center">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Is there something I can do?
Thanks in advance :)
Use this xaml file & compare with your file so that you will get idea what mistake you was making
I realize the issue was using android:gravity (in second & third LinearLayout) along with android:weight which was pushing your layout toward top.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/main_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="610.3dp">
<TextView
android:text="Location Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView9"
android:layout_marginTop="0dp"
android:gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="199.3dp"
android:id="#+id/linearLayout1"
android:layout_marginTop="0dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout2">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout3"
android:layout_marginTop="5dp">
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView4"
android:width="100dp"
android:gravity="center|left|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView5"
android:gravity="center|top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailAddress" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/linearLayout4"
android:layout_marginTop="5dp"
android:gravity="top">
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView6"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView7"
android:gravity="center|top" />
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailDescription" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="Registered User"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_marginTop="10dp"
android:gravity="center" />
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/recyclerViewLocationUser"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressBarLocationDetail"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="50dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ff03a9f4"
android:layout_gravity="right"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
I'm trying to stack two vertical LinearLayout in LinearLayout horizontally.
My code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtusername" />
<TextView
android:text="Date registration"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtdateregistr" />
<TextView
android:text="Phone number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtphonenumb" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="horisontal"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercountnumb" />
<TextView
android:text="Ordr"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercount" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycountnumb" />
<TextView
android:text="Delv"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycount" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Also everything looks as I and has conceived:
And the scheme for full understanding:
But when I compile that in VS2015 see error "String types not allowed (at 'orientation' with value 'horisontal')". Need help
Its a typo.
Change,
android:orientation="horisontal"
to
android:orientation="horizontal"
In the root use below attribute
wheightSum="10"
and in child view use wheight = "5" for each child view
Note: on base layout use android:orientation="horizontal" for horizontal display or android:orientation="vertical" for vertical display
Error in LinearLayout orientation.It should be horizontal or remove this.(By default Linear layout has horizontal orientation. )
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtusername" />
<TextView
android:text="Date registration"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtdateregistr" />
<TextView
android:text="Phone number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtphonenumb" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercountnumb" />
<TextView
android:text="Ordr"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercount" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycountnumb" />
<TextView
android:text="Delv"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycount" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I got a problem with an .xml file of an Android project.
Particularly, I need to have a Scroll View for the major part of the screen a footer underneath.
The ScrollView is the parent of a LinearLayout which keeps three LinearLayouts inside.
The first twos LinearLayout are correctly shown, but the third has never been shown.
I don't understand the reason why it happens: if I put the third LinearLayout in first position, everyone is correctly showed.
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AppInfo"
android:padding="5dp"
android:id="#+id/bread" />
<HorizontalScrollView
android:id="#+id/horizontal_scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout_image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:gravity="fill_horizontal"
android:layout_gravity="top"
android:id="#+id/attivita_linear"
android:padding="10dp"
android:isScrollContainer="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome Attività "
android:id="#+id/textView_nome"
android:layout_gravity="center_vertical|center_horizontal"
android:textSize="30dp"
android:paddingBottom="35dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Indirizzo: "
android:id="#+id/textView_indirizzo"
android:textSize="20dp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telefono: "
android:id="#+id/textView_tel"
android:textSize="20dp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email: "
android:id="#+id/textView_email"
android:textSize="20dp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="www: "
android:id="#+id/textView_www"
android:textSize="20dp"
android:textIsSelectable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Descrizione: "
android:id="#+id/textView_descrizione"
android:textSize="20dp"
android:textIsSelectable="false" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#000000"
android:gravity="fill_horizontal"
android:layout_gravity="top"
android:id="#+id/attivita_buttons"
android:padding="10dp"
android:isScrollContainer="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"
android:background="#drawable/ic_action_call"
android:contentDescription="prova" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/cola">
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
Hope you can help me.
Any answer would be appreciated.
Set above attribute to your scrollview
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:above="#+id/footer">
Bottom part of your ScrollView is getting covered by your footer view. Setting your ScrollView above it will let you scroll entire list.
You can also easily done this using LinearLayout .
Note : textSize value is always given "sp" instead of "dp" for this look at this one Link
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AppInfo"
android:padding="5dp"
android:id="#+id/bread" />
<HorizontalScrollView
android:id="#+id/horizontal_scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout_image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:gravity="fill_horizontal"
android:layout_gravity="top"
android:id="#+id/attivita_linear"
android:padding="10dp"
android:isScrollContainer="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome Attività "
android:id="#+id/textView_nome"
android:layout_gravity="center_vertical|center_horizontal"
android:textSize="30sp"
android:paddingBottom="35dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Indirizzo: "
android:id="#+id/textView_indirizzo"
android:textSize="20sp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telefono: "
android:id="#+id/textView_tel"
android:textSize="20sp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email: "
android:id="#+id/textView_email"
android:textSize="20sp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="www: "
android:id="#+id/textView_www"
android:textSize="20sp"
android:textIsSelectable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Descrizione: "
android:id="#+id/textView_descrizione"
android:textSize="20sp"
android:textIsSelectable="false" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#000000"
android:gravity="fill_horizontal"
android:layout_gravity="top"
android:id="#+id/attivita_buttons"
android:padding="10dp"
android:isScrollContainer="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"
android:background="#drawable/ic_action_call"
android:contentDescription="prova" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/cola">
</FrameLayout>
</RelativeLayout>
</LinearLayout>
I'm having a hard time dealing with a scroll view. I need to add some buttons to a LinearLayout inside of it during run time. My problem is that at the begining, that layout should be empty, but still, scrollable by the scrollview even if there isn't enough elements inside of it to be out of screen space.
Is there anyway to make this happen?
I have tried several things, but nothing seems to work.
Thank you very much in advanced.
*Please ignore textViews inside of LinearLayouts, as those are only examples of contents.
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3.15"
android:background="#drawable/borde_negro"
android:fadeScrollbars="false"
android:fillViewport="true">
<LinearLayout
android:id="#+id/vlPentagrama"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/borde"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/TextView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/borde" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
Basically it's a page of text and pics with ads at the bottom. It works fine on smaller devices like phones, but on larger like tablets there is a problem....more of a user dislike thing.
If the content of page is small then ads, which comes correctly at the end of content actually comes in the middle of the screen.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/vnaslov"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginLeft="7dp"
android:gravity="left"
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:id="#+id/vautor"
android:layout_below="#+id/vnaslov"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
/>
<TextView
android:id="#+id/vdatum"
android:layout_toRightOf="#+id/vautor"
android:layout_below="#+id/vnaslov"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
/>
<TextView
android:id="#+id/vlid"
android:layout_below="#+id/vdatum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:layout_marginLeft="7dp"
android:textSize="16sp"
android:textStyle="bold"
/>
<com.loopj.android.image.SmartImageView
android:id="#+id/vslika"
android:layout_below="#+id/vlid"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_margin="5dp"
/>
<TextView
android:id="#+id/vtijelo"
android:layout_below="#+id/vslika"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginLeft="7dp"
android:textSize="16sp" />
<Button
android:id="#+id/videobutton"
android:layout_below="#+id/vtijelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/dugme_video"/>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<com.google.ads.doubleclick.DfpAdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
</ScrollView>
It works if it's simple like this...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/wrap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="#+id/but1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="But1" >
</Button>
<Button
android:id="#+id/but2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="But2" >
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>`
But not if it's filled with my content like the above in my question. First linearlayout with content up to the ad, and second with just the ad...
How would the content inside linearlayout be a problem?
Why?
The trick is to use layout_weight="1" and fillViewport="true" on the ScrollView.
This should do the trick:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativemain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollmain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/wrap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
//put your content here
</LinearLayout>
<LinearLayout
android:id="#+id/myadv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
//this is your advertisement
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>