Android. ScrollView is shown beneath of previous layout - android

I have two linear layouts and ScrollView in my layout.
I add a few views to ScrollView programmatically.
All is okay, if views in ScrollView are inside of the screen.
But if more views in ScrollView, the first view of scrollview
is under layout2 and partly invisible.
I tryed relative layout. But the same performance.
Of course I'd like to see top element of scrollview without truncating.
My XML is below:
<?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/backNormal"
android:orientation="vertical"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageDriverWaitingBack"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_weight="1"
android:src="#drawable/back"
android:gravity="left"
/>
<TextView
android:id="#+id/textDriverWaitingTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:gravity="center"
android:textColor="#color/text1"
android:layout_weight="2.13"
/>
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:gravity="right"
android:layout_weight="1"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/backDark2"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="horizontal"
>
<Button
android:id="#+id/dButtonWaitMinus"
android:text='-'
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
style="#style/button_style_normal"
android:layout_weight="1"
/>
<TextView
android:id="#+id/dTextWaitDist"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Distance"
android:gravity="center"
android:textColor="#color/text1"
android:layout_weight="9"
/>
<Button
android:id="#+id/dButtonWaitPlus"
android:text='+'
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
style="#style/button_style_normal"
/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/driverWaitList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="vertical"
android:layout_gravity="center_horizontal|center_vertical"
>
</LinearLayout>
</ScrollView>
</LinearLayout>
Any ideas please! Thanks!

Related

How to edit Layout to full length of screen?

i have an app which has a main RelativeLayout and some LinearLayout within it.
My problem is that the LinearLayout doesn't fit to the full lenght of the screen:
this is my xml file :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/bgApp" >
<LinearLayout
android:id="#+id/mainView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="#dimen/topBarHeight"
android:background="#drawable/top"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#android:color/transparent" >
<ImageView
android:id="#+id/scoreLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/coin_icon"
android:contentDescription="#string/app_name"/>
<TextView
android:id="#+id/mainScreenTotalPoints"
style="#style/pointTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/btnPaddingV"
android:text="#string/startPoint"
android:textSize="#dimen/buttonTextSize" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/logPadding"
android:text="#string/app_name"
android:textColor="#d0105e"
android:textSize="27sp"
android:textStyle="bold"/>
<LinearLayout
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/btnPadding"
android:paddingRight="#dimen/btnPadding" >
<Button
android:id="#+id/play"
android:layout_width="fill_parent"
android:layout_height="#dimen/buttonHeight"
android:background="#drawable/button_blue"
android:gravity="center"
android:onClick="onButtonClickPlay"
android:text="#string/play"
android:textColor="#color/btnMain"
android:textSize="#dimen/buttonTextSize" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="vertical"
android:paddingTop="#dimen/mainbox" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/btnPadding" >
<Button
android:id="#+id/btn_how"
style="#style/btnCapital"
android:layout_width="fill_parent"
android:layout_height="#dimen/buttonHeight"
android:layout_marginRight="#dimen/btnPaddingV"
android:layout_weight="1.0"
android:background="#drawable/button_green_how"
android:onClick="onButtonClickHowToPlay"
android:text="#string/howInfo" />
<Button
android:id="#+id/btn_rate"
style="#style/btnCapital"
android:layout_width="fill_parent"
android:layout_height="#dimen/buttonHeight"
android:layout_marginLeft="#dimen/btnPaddingV"
android:layout_weight="1.0"
android:background="#drawable/button_rate"
android:onClick="onButtonClickRate"
android:text="#string/rateInfo" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/btnPadding" >
<Button
android:id="#+id/sound"
style="#style/btnCapital"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="#drawable/mute_01"
android:gravity="center"
android:onClick="onButtonClickSound"
android:text="#string/mute" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/btnPadding" >
<Button
android:id="#+id/moreapp"
style="#style/btnCapital"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="#drawable/button_blue"
android:gravity="center"
android:onClick="onButtonClickMoreApp"
android:text="#string/moreapp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
ads:adSize="BANNER"
ads:adUnitId="#string/admob_publisher_id"
android:gravity="bottom" />
</LinearLayout>
</LinearLayout>
</ScrollView>
here is a screenshot :
Screenshot after running app
and here a screenshot of layout before running app:
Screenshot before running app
Thank you in advance !
You need to use the ScrollView attribute called android:fillViewport="true". This attribute causes the scroll view’s child to expand to the height of the ScrollView if needed.
When the child is taller than the ScrollView, the attribute has no effect.
Check out this for detail explanation.
You have to use attribute android:fillViewport="true".in your scrollview.

Android App 50 percent width

I am trying to build a little Android App and I need two LinearLayout side by side. (50/50)
How it looks:
http://i.stack.imgur.com/C9yCF.png
I already try to use: android:layout_width="0dp" android:layout_weight="1" but it didn't work.
This is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/part">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="9pt"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:baselineAligned="true"
android:background="#ff7f7f7f"
android:id="#+id/head">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="123456789"
android:id="#+id/textView"
android:paddingStart="3pt"
android:paddingLeft="3pt"
android:textColor="#ffffffff"
android:singleLine="false" />
</LinearLayout>
<LinearLayout
android:id="#+id/left"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/head"
android:background="#ffff0100" >
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/head"
android:background="#fffcff00" />
How it should look:
http://i.stack.imgur.com/tup01.png
Have one more LinearLayout with horizontal orientation below your #+id/head LinearLayout.
Set its width to match_parent. Keep the last two LinearLayouts inside the new LinearLayout and have android:layout_weight=0.5 for both. Something like:
<RelativeLayout>
<LinearLayout> </LinearLayout>
<LinearLayout
...
android:orientation:"horizontal"/>
<LinearLayout
android:weight="0.5"
android:width="0dp"
... />
</LinearLayout>
<LinearLayout
android:weight="0.5"
android:width="0dp"
... />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
You can't use layout_weight with RelativeLayouts children. Put/Wrap both LinearLayouts in another LinearLayout.
Hey try this code...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/part"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/head"
android:layout_width="fill_parent"
android:layout_height="9pt"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#ff7f7f7f"
android:baselineAligned="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3pt"
android:paddingStart="3pt"
android:singleLine="false"
android:text="123456789"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/head"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/left"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0100"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#fffcff00"
android:orientation="vertical" />
</LinearLayout>

android: lock view at bottom of page under listview

I am trying to have a locked position linear layout within a relative layout.
There should be a listview and at the botoom of the page a linear layout with 2 checkboxes.
The problem is that the last item in the listview can never be seen as it is hiding under the linearlayout.
Help appreciated!
My layout xml file:
<?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"
android:orientation="vertical"
android:background="#color/light_gray" >
<ListView
android:id="#+id/choose_children_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:dividerHeight="5dip"
android:divider="#color/light_gray"
android:padding="5dip">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#color/white"
android:layout_marginTop="4dip">
<CheckBox
android:id="#+id/childCheckAllTextView"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
android:checked="true"
android:text="#string/check_all" />
<CheckBox
android:id="#+id/childUncheckAllTextView"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="1"
android:checked="false"
android:text="#string/uncheck_all" />
</LinearLayout>
</RelativeLayout>
add id to linearlayout and make your listview "above" linearlayout
<?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"
android:orientation="vertical"
android:background="#color/light_gray" >
<ListView
android:id="#+id/choose_children_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:dividerHeight="5dip"
**android:above="#+id/mywrapper"**
android:divider="#color/light_gray"
android:padding="5dip">
</ListView>
<LinearLayout
**android:id="#+id/mywrapper"**
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#color/white"
android:layout_marginTop="4dip">
<CheckBox
android:id="#+id/childCheckAllTextView"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
android:checked="true"
android:text="#string/check_all" />
<CheckBox
android:id="#+id/childUncheckAllTextView"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="1"
android:checked="false"
android:text="#string/uncheck_all" />
</LinearLayout>
</RelativeLayout>

3 layouts - middle is flexible

I need the following thing:
3 layouts:
Header
Content
Footer
Header must be on the top footer must be sticked to the bottom (android:layout_alignParentBottom="true").
But how to make middle to occupy the whole other screen? Thanks.
Here is my solution (with android:layout_weight and ScrollView):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Header"
tools:ignore="HardcodedText" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Content"
tools:ignore="HardcodedText" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Footer"
tools:ignore="HardcodedText" />
</LinearLayout></LinearLayout>
And the result picture :
Hi Use the following lines
<?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"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Button" >
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Header" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/linearfooter"
android:layout_below="#+id/button1"
android:background="#android:color/darker_gray"
>
</LinearLayout>
<LinearLayout
android:id="#+id/linearfooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" >
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="footer" />
</LinearLayout>
</RelativeLayout>
hope this helps you.
Use a height of 0dp and
android:layout_weight
set to 1
Finally I've got the next solution:
To the middle layout I added:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
android:layout_weight="1">
And it works!

Android: Horizontal scrollview issue

I am facing layout issues while using the horizontal scrollview to scroll images with checkboxes
below is my layout
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/mygallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
</LinearLayout>
</HorizontalScrollView>
i am using this scrollview in a listview which is in another layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/albumsearch"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<ListView
android:id="#+id/albumdetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:paddingBottom="5dp" >
</ListView>
</LinearLayout>
below is the layout with my image and checkbox
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<CheckBox
android:id="#+id/selectedImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/icon"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:layout_marginTop="20dp"
android:checked="true" />
<ImageView
android:id="#+id/icon"
android:layout_width="72dp"
android:layout_height="75dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
but when i am running this code in small screen devices i can see only half image, how to get full image, any help is appreciated.
Solved: After Changing my layout with checkbox and imageview to linearlayout and used weight attribute
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="left"
android:orientation="vertical"
android:layout_weight="1" >
<CheckBox
android:id="#+id/selectedImg"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:checked="true"
android:layout_weight="1"
android:gravity="center" />
<ImageView
android:id="#+id/icon"
android:layout_width="72dp"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" />
</LinearLayout>

Categories

Resources