my activity contains 4 section as follow:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"></LinearLayout>
<ScrollView>
<LinearLayout></LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"></LinearLayout>
</RelativeLayout>
what is the correct layout properties for scrollview?
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- put your scrolling stuff here it needs
to exceed the height of the view to scroll -->
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
I believe this should work..
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- your layouts.. -->
<!-- layouts in here will be in the scrollview -->
</LinearLayout>
</ScrollView>
</LinearLayout>
Related
This is the code written in main Layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
>
</LinearLayout>
I need two linear layouts inside this parent layout such that the parent layout gets split into two halves..
Use this code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
//Other Stuff
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
//Other Stuff
</LinearLayout>
</LinearLayout>
You can use below code,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:weightSum="2"
android:orientation="vertical">
<LinearLayout
android:background="#android:color/black"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--child 1-->
</LinearLayout>
<LinearLayout
android:background="#android:color/holo_blue_dark"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--child 2-->
</LinearLayout>
</LinearLayout>
we have use layout_weight to create these type of layout.
try this code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:weightSum="1"
android:orientation="vertical">
<!--First Row-->
<LinearLayout
android:background="#android:color/black"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5">
</LinearLayout>
<!--Second Row-->
<LinearLayout
android:background="#android:color/holo_blue_dark"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5">
</LinearLayout>
</LinearLayout>
My LinearLayout with a TextView is not showing in a fragment layout.
The Content under the LinearLayout with the ImageView is not displayed.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<!-- Other content -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--
This TextView is not displayed
-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DUMMY"/>
</LinearLayout>
</ScrollView>
When you use ScrollView you can have only one child.
So your view must something like this
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!-- Your content -->
</LinearLayout>
</ScrollView>
Here Your content is
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<!-- Other content -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--
This TextView is not displayed
-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DUMMY"/>
</LinearLayout>
You can't have multiple LinearLayouts in ScrollView. Try wrapping them inside a single LinearLayout. Something along the following lines should work,
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<!-- Other content -->
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DUMMY"/>
</LinearLayout>
</ScrollView>
You can not have two layers in the scroll view
The scroll visually embeds a layer inside and the other layers are inside it
you can use sample
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DUMMY"/>
</LinearLayout>
</LinearLayout>
My goal is to show a toolbar at the top of the view, then a TextView, then a ScrollView section and then a footer that always shows at the bottom of the view. The below only shows the toolbar and the TextView header. Nothing is showing for the ScrollView section or for the footer at the bottom. What am I missing here?
EditActivity.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:focusableInTouchMode="true"
tools:context=".EditActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" >
</include>
<RelativeLayout android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="#+id/toolbar" >
<TextView
android:id="#+id/create_skycard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/colorFlLabelFinal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:clickable="false" />
</RelativeLayout>
<RelativeLayout android:id="#+id/myFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ViewFlipper
android:id="#+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp" >
<include layout="#layout/cardview_nobuttons"
android:id="#+id/cardviewNobuttons" />
<include layout="#layout/cardview_previewbuttons"
android:id="#+id/cardviewPreviewbuttons" />
</ViewFlipper>
</RelativeLayout>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header"
android:layout_above="#+id/myFooter"
android:fillViewport="true" >
<LinearLayout
android:id="#+id/LinearLayout1"
style="#style/scrollbar_shape_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.wimso.v108.widget.EditText
... />
</LinearLayout>
</ScrollView>
</RelativeLayout>
First of all, you should limit height of footer view. I set the ViewFlipper's height to 128dp for test, so you can calculate your own based on its content.
Second: You should set android:layout_alignParentTop="true" for the include which its id is toolbar. To do this you should set height and weight for it as I did.
Third: The height of the ScrollView should be wrap_content instead of match_parent to be sure it stretches between header and footer views.
Here is your layout source code after applying the above corrections:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:focusableInTouchMode="true"
tools:context=".EditActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:gravity="center_horizontal">
<TextView
android:id="#+id/create_skycard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorFlLabelFinal"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/myFooter"
android:layout_below="#+id/header"
android:fillViewport="true">
<LinearLayout
android:id="#+id/LinearLayout1"
style="#style/scrollbar_shape_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.wimso.v108.widget.EditText
... />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/myFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ViewFlipper
android:id="#+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="128dp"
android:layout_marginBottom="5dp">
<include
android:id="#+id/cardviewNobuttons"
layout="#layout/cardview_nobuttons" />
<include
android:id="#+id/cardviewPreviewbuttons"
layout="#layout/cardview_previewbuttons" />
</ViewFlipper>
</RelativeLayout>
</RelativeLayout>
I've got a ScrollView which occupies the bottom half of the screen.
Inside this ScrollView a put a LinearLayout (vertical) with a lot of content.
When I start the activity, the content somewhy automatically scrolls itself down so that it starts at the top of the window. But I need it to start at the top of the ScrollView (i.e. at the center of the window).
What am I doing wrong?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.intrigue.activities.EditActivity"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:visibility="visible">
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView2"
android:background="#color/colorDarkBack">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<!-- content -->
</LinearLayout>
</ScrollView>
</LinearLayout>
you can do like below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.45"
android:orientation="vertical">
<ImageView
android:id="#+id/frag_home_iv_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/demo" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.55"
android:fadeScrollbars="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.26"
android:gravity="center"
android:orientation="horizontal"
android:padding="#dimen/padding_5dp"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:src="#drawable/demo" />
<TextView
android:id="#+id/fragment_home_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:paddingLeft="#dimen/padding_5dp"
android:text="#string/demo"
android:textColor="#color/BlackColor" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Your problem solve by below code :
When open your activity call below code:
your_scroll_view.post(new Runnable() {
#Override
public void run() {
your_scroll_view.fullScroll(View.FOCUS_DOWN);
}
});
Best of luck
You can achieve the desired results by using layout_weight property:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- your content here-->
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- your content here-->
</LinearLayout>
</ScrollView>
</LinearLayout>
Let me know if it helped you.
I am creating UI like as per below code
View pager with images and then other UI controls.
It is working fine with 2-3 controls, but if UI is out of page with 10 UI controls then scroll view not wokring.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="true"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<android.support.v4.view.ViewPager
android:id="#+id/scheduleViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/create_account_create_password" />
// Other UI controls
</LinearLayout>
</LinearLayout>
</ScrollView>
Please try this below code ...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp">
<android.support.v4.view.ViewPager
android:id="#+id/scheduleViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/create_account_create_password" />
// Other UI controls
</LinearLayout>
</LinearLayout>
</ScrollView>