Android RelativeLayout issue - android

I've got a RelativeLayout with two nested RelativeLayouts. I want first RL to stay on top and second to be scrollable, but this does not work.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/relativeTop"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--Buttons-->
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--Lots of nested RelatiLayouts with Views-->
</RelativeLayout>
</ScrollView>
</RelativeLayout>

There is an xml attribute you need to know for that android:layout_below
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/relativeTop"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--Buttons-->
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/relativeTop"> <!-- here it goes! -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--Lots of nested RelatiLayouts with Views-->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
An alternative is LinearLayout which works great for there layouts as it can "divide" your layout into the two parts...

Related

How to fix ListView inside ScrollView?

I need to put a ListView inside ScrollBar. I know there is other question about this theme but the answers are very complex and bad.
The ListView doesn't show all its elements, only the first one.
The main structure of my relevant code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....MORE ELEMENTS....
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
></ListView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Put your ListView in a separate LinearLayout parent or you can add it in a separate .xml file according to your choice and add
android:fillViewport="true"
in your scrollview, like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!....MORE ELEMENTS....>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

How can I add two Scroll views in a xml layout such that each scrollview take half of the height of the layout?

How do I add two ScrollViews in an android XML-layout such that each scroll view takes half of the height of the layout?
You can use LinearLayout as rootview then add two ScrollView as child and assign android:layout_weight="1" to both ScrollView
Note : if you want your view scroll horizontally then use HorizontalScrollView
SAMPLE 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="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/black"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add viw here-->
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/holo_red_dark"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add viw here-->
</LinearLayout>
</ScrollView>
</LinearLayout>
OUTPUT
There is a multiple way to do this. I am suggesting you one simple way.
try to add weightsum =2 inside parent layout. And devide layout with 1 like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2.0" >
<RelativeLayout
android:id="#+id/child_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#0000FF" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/child_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#00FF00" >
</RelativeLayout>
</LinearLayout>

Problems placing view on top of SlidingPaneLayout

I want to place a view via include on top of a SlidingPaneLayout. In the layout preview of AndroĆ­d Studio it is displayed correctly but on my device the view won't show - why?
Here is the complete layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/online_state"
android:layout_height="5dp"
android:layout_width="wrap_content"/>
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/content_view_spl"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_primary"
android:orientation="vertical" >
<de.timroes.android.listview.EnhancedListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/color_background_primary"
android:divider="#color/black"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/selected_item"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>
Ok, got it...
I have to place the SlidingPaneLayout below the view...
Stupid question... sorry ;)

Scrolling issue - Android Scrollview

I seem to be having an issue getting my app to scroll fully. I think there is an issue with the linear layout but would like your help to solve this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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"
android:orientation="vertical"
tools:context="com.app.aks.fragments.ThreeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
//// some image and text views //////
</LinearLayout>
</LinearLayout>
</ScrollView>
The window only scrolls partially and not all the way to the bottom....Suggestions?
In your MainActivity.java
Or whereever you are using/initializing these views.
Try this for all the textviews/image views. which are nested inside.
view.setMovementMethod(new ScrollingMovementMethod());
The direct child of ScrollView should be another layout that supports multiple children, such as RelativeLayout or LinearLayout.
<?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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton ... />
<TextView ... />
<TextView ... />
<TextView ... />
</ScrollView>
Try with setting android:fillViewport="true" on the ScrollView:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

Android cannot re-size LinearLayout

I've been working on an android application recently, and in the last day or so I've been working on the GUI using the eclipse layout editor. Unfortunately, I can't resize my linearlayout in any way other than the x-dimension. I can also resize it by resizing the TextView contained within it. As sushil stated, I can't control the height of my linearlayout. My 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="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/helpLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="horizontal" >
<TextView
android:id="#+id/InfoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info:"
android:textSize="35sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this. Add android:fillViewport="true" to the ScrollView
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
I don`t know if I understood what you want, but try to change this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
to this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
this way, it will fill the screen when size is different.

Categories

Resources