I want to define a composite layout where the header and footer LinearLayout blocks take 10% of the view and body block the remaining 80%. Without setting weights, all 3 blocks have the same size, so I have set the weight of header and footer layout to 10 and body to 80 with weight sum 100 but this had an unwanted result that actually is opposite to the one expected, and body despite has the higher weight disappears due to the fact header and footer block take all the available space.
Layout code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/head"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#drawable/hf"
android:padding="5dp">
<TextView
android:id="#+id/texthead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sample head" />
<ImageView
android:id="#+id/imageh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/him" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="80"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/bd0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#drawable/bdf"
android:padding="10dp">
<TextView
android:id="#+id/textbd0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:gravity="center"
android:text="Lorem ipsum" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/bdim" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bd1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#drawable/bdf"
android:padding="10dp">
<TextView
android:id="#+id/textbd1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:gravity="center"
android:text="Lorem ipsum" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/bdim" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/ft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#drawable/ftf"
android:padding="5dp">
<TextView
android:id="#+id/textft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sample footer" />
<ImageView
android:id="#+id/imageft"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/ftim" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Try the following code:
(You can undo the background changes I did, it was just so I could visualize what was going on.)
According to the following post: Android layout weight not working as I thought -- you need to set your wanted attribute to 0dp for layout_weight to work properly.
In summary: by setting the height to match_parent, you are confusing the XML compiler and it doesn't know how to apply layout_weight properly.
<?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"
android:weightSum="100">
<LinearLayout
android:id="#+id/header"
android:background="#color/material_dynamic_neutral30"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/head"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/black"
android:padding="5dp">
<TextView
android:id="#+id/texthead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sample head" />
<ImageView
android:id="#+id/imageh"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="80"
android:background="#color/teal_200"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/bd0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/cardview_light_background"
android:padding="10dp">
<TextView
android:id="#+id/textbd0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:gravity="center"
android:text="Lorem ipsum" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bd1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/teal_200"
android:padding="10dp">
<TextView
android:id="#+id/textbd1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:gravity="center"
android:text="Lorem ipsum" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:background="#color/teal_700"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/ft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/material_dynamic_neutral30"
android:padding="5dp">
<TextView
android:id="#+id/textft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sample footer" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Related
I want to get huge view, which I have to scroll. I want to get a one part of of view always on a phone screen in my code is a LinearLayout I want to display always on screen. Into my LinearLayout I put layout_alignParentTop but when I scroll it disappears.
My code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/iv_photo"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="3.5">
<TextView
android:id="#+id/tv_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jan Nowak"
android:textColor="#color/background_tutorial"
android:textSize="#dimen/text_normal_size"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_user_mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_user_name"
android:text="jan.nowak#gmail.com"
android:textColor="#color/background_tutorial"
android:textSize="#dimen/text_normal_size" />
</RelativeLayout>
<ImageView
android:id="#+id/iv_settings"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Made few changes:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<ImageView
android:id="#+id/iv_photo"
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="3.5">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_user_name"
android:textColor="#000000"
android:textSize="17sp"
android:text="Jan Nowak"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_user_name"
android:id="#+id/tv_user_mail"
android:textColor="#000000"
android:textSize="17sp"
android:text="jan.nowak#gmail.com"
/>
</RelativeLayout>
<ImageView
android:id="#+id/iv_settings"
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
If you want to keep a view static and other scrollable and keep that view outside of your scrollview....
I want to build the following screen which contains app logo, success/failure icon image, information message and ok button.
Here this the code. I am using linear layout to achieve this.
<LinearLayout
android:id="#+id/statusLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#android:color/white"
android:weightSum="2"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="#+id/statusTopRelativeLayout"
android:background="#android:color/holo_blue_bright"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:id="#+id/client_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/no_image_description"
android:src="#drawable/client_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/statusBottomRelativeLayout"
android:background="#android:color/holo_blue_light"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/statusText"
android:textSize="50sp"/>
<Button
android:id="#+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/statusText"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:clickable="true"
android:focusable="true"
android:onClick="goToHomeScreen"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:text="#string/ok"
android:textColor="#ffffff"
android:textSize="40sp"/>
</RelativeLayout>
How to place success/failure icon image on top of the two layouts?
You can use constraint to make it easy
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.Guideline
android:id="#+id/center"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/center"
android:background="#ffffff"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#id/center"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#00ffff"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ff8801"
app:layout_constraintTop_toTopOf="#id/center"
app:layout_constraintBottom_toBottomOf="#id/center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
Output:
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/nilu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:orientation="vertical"
android:paddingBottom="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
<LinearLayout
android:id="#+id/nilu2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/nilu"
android:layout_weight="1"
android:background="#color/colorAccent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#mipmap/ic_launcher_round" />
</RelativeLayout>
</RelativeLayout>
OUTPUT
Parent RelativeLayout
add child LinearLayout as fillParent and assign weightsum 2. add two
layouts with 1 weight each. (add individual implementation for each
layout according to your requirements.)
add second child in relative
layout as imageview/button for that good sign and set it center in
parent.
This will fix your problem
As for most of you: we design our screens for our app in photoshop and then try to transfer them into Visual Studio.
This is a screenshot of our app FROM PHOTOSHOP:
You could imagine, the further we go the harder it gets. The center screen was easy but the left and right one - oh boy...
Anyway, today I'm here for the right one.
As you can see, there are these headlines such as: "Show Us Love For Asia".
This whole box shows a photo, a headline, a few extra infos AND:
a profile picture.
The whole is a scrollview and the white bars underneath each box are actually pngs. The reason is, that we need them to be equally sized on each different platform. Anyway - the profile picture is overlapping the picture box and the white divider png in between the picture boxes.
And here is the question: how the hell would we implement that into our axml?
As far as the screen is, this is it in xml:
<?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:id="#+id/layoutadventure"
android:background="#android:color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="17"
android:layout_height="0dp"
android:background="#23313e"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:src="#drawable/sub_category_europe"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_weight="30"
android:id="#+id/imgSubchallenge" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="40"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center|bottom"
android:id="#+id/txtSub"
android:layout_weight="60"
android:gravity="center|bottom"
android:text="Positive Thinking"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold|italic" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_gravity="top|center"
android:gravity="top|center"
android:src="#drawable/dotted_line_challenges" />
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="35"
android:layout_height="0dp"
android:orientation="vertical" />
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:src="#drawable/bar2"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_weight="5" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="25"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="30"
android:orientation="vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="Total"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="Done"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="Exp"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="25"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="30"
android:orientation="vertical" />
<TextView
android:id="#+id/totalChallenges"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="Total"
android:gravity="right"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/totalChallengesDone"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="Done"
android:gravity="right"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/totalXP"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="Exp"
android:gravity="right"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="25"
android:orientation="vertical" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="vertical" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="82.5"
android:scrollbars="none"
android:id="#+id/scrlview">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/linlayout"
android:orientation="vertical" />
</ScrollView>
</LinearLayout>
So you probably see the dilemma: the profile picture is halfway in one column of the scrollview and halfway in another column.
Can you provide any help for that? THANKS SO MUCH :)
Try this i hope this will help you. This is for only "Show Us Love For Asia" one item only.
<?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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="500dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:orientation="vertical"
android:background="#color/colorAccent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8"
android:background="#color/colorPrimary">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"
android:background="#color/colorAccent">
</LinearLayout>
</LinearLayout>
<android.support.v4.widget.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher_round"
android:layout_gravity="bottom"
android:layout_marginBottom="75dp"/>
</FrameLayout>
</LinearLayout>
Hi I'm learning Android.
Here is the code for my Layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="com.example.android.aidsdruginformation.DetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
UI Screen shot:
How I want my UI to look:
Why is the second LinearLayout not showing?
Am I doing something wrong?
While using layout_width should the parent element have a fixed dimension?
Please advice..
Link to my Repo:
https://github.com/MukundPradeep/AidsDrugInformation
Going through my Repo,
I figured that the activity_detail.xml under the layout v-17 folder was being used by the framework because the android:textAlignment="center" attribute I have used is only available for API 17+. My target SDK is 23.
Therefore the layout I posted(under layout directory) would only show on devices running versions of Android less than 17.
If you are planning to use the above mentioned attribute, please make sure you implement your layout changes in all the layout folders generated for different APIs.
Thanks everyone for trying to help me out.
you can use android:fillViewport
Defines whether the scrollview should stretch its content to fill the
viewport.
Must be a boolean value, either "true" or "false".
You should try with below approach . make LinearLayout as root .
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
// Your Staff
</ScrollView>
</LinearLayout>
Try, added some attribute to ScrollView ,
android:fillViewport="true",
android:isScrollContainer="true"
add LinearLayout as parent of ScrollView
<?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
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:isScrollContainer="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8" />
</LinearLayout >
</ScrollView >
</LinearLayout >
I tried with your code and it is showing
try this way
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
tools:context="com.example.android.aidsdruginformation.DetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
OUTPUT
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="com.example.android.aidsdruginformation.DetailActivity">
<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">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
You are giving the first layout weight as 1. Which will take the full height of screen. You can divide it. But also inside scrollview if you give weight then what is the use of that scrollview.
check this .and make it as right if its helpful.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_weight="1"
android:id="#+id/l1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Now book a ride at 6Rs/km with uber go"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="7/11 supermarket get special discounts today only"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/l1"
android:padding="10dp"
android:layout_weight="1"
android:id="#+id/l2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="10% discount on all meals"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Clearance sale upto 40% off"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="201dp"
android:layout_below="#id/l2"
android:layout_weight="1"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Starbucks coffee try our special new mocha latte for a limited period discount"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Buy 2 get 1 free*"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
Just give parent linear layout this attribute:
android:weightSum="2" then your both child linear layout are Shown on Screen.
Wrap your two linear layouts with another linear layout with vertical orientation(as shown in the many comments). In your case both the linear layouts are overlapping each other so you see just one.
Unless it has enough items to scroll, it can not be scrollable.
I want to keep an ImageView's position fixed in a native android app, that is, it shouldn't move when a user scrolls.
In other words, I want the same effect what happens with css position:fixed in a web page.
The layout code is like:
<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"
tools:context=".ui.ProductDetailActivity">
<ImageView
android:id="#+id/product_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:layout_margin="#dimen/activity_horizontal_margin">
<TableRow>
<TextView
android:id="#+id/product_model_label"
android:layout_width="match_parent"
android:layout_height="32dp"
android:text="#string/product_model_label"
style="#style/ProductDetail"/>
<TextView
android:id="#+id/product_model"
android:layout_width="match_parent"
android:layout_height="32dp"/>
</TableRow>
</TableLayout>
I want the TableLayout to scroll over the image.
NOTE: My actual layout file has more table rows.
add image view outside the scroll view . look at this example
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sensor.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_gravity="center"/>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:padding="100dp"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test 1"
android:padding="50dp"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test 2"
android:padding="50dp"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
use relative layout. .
<ImageView
android:id="#+id/product_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
you can add other parameters like alignParentLeft, center_Horizontal etc.