LinearLayout not Displaying - android

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.

Related

overlapping a screen in android

In the below layout i have a text view named as scanning device.In that am displaying a device name But my device list was displaying above the screen .
can any one please help me how to scroll view should be inside the device list.while scrolling the screen it was displaying the list of the devices but it is displaying above the screen.
want to display inside a screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="#string/back"
android:textAllCaps="true"
android:textColor="#color/white"
android:visibility="invisible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:padding="10dp"
android:textStyle="bold"
android:text="#string/lamp_list"
android:textAllCaps="true"
android:textColor="#color/white" />
<TextView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableRight="#drawable/refresh"
android:gravity="right"
android:padding="10dp"
android:textAllCaps="true"
android:textColor="#color/white" />
<ProgressBar
android:id="#+id/scanningProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="#drawable/baground"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="#string/start_discovery"
android:textColor="#color/white"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
In the below layout connect textview was coming out of the layout.
device_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="6dp"
android:src="#drawable/lamp" />
<TextView
android:id="#+id/deviceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:textColor="#color/white"
android:textSize="17sp"
tools:text="Solar Enviro SSL 2016" />
<TextView
android:id="#+id/connect"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:background="#drawable/rounded_red_view"
android:text="#string/connect"
android:paddingBottom="1dp"
android:paddingTop=".2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/white"
android:textSize="17sp" />
</LinearLayout>
change this things..
used both wrap_content. i hope you also remove default action bar.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Instead of CoordinatorLayout use linear layout.
if u r a beginner start coding with linear layout. It is easy to understand.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

layout_below in relative layout won't show

i'm trying to make a layout_below the cardview in relative layout but it wont show up in my device where layout_above works. i dont know why it wont work. i think it should be work because it below the cardview. please help what did i miss or wrong.
this is my xml code
<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="#drawable/background_2"
tools:context=".ExchangeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/saldo"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/holder" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Will Stitch"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="#+id/saldo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Saldo"
android:textColor="#color/colorPrimary"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/saldo"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch#gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
please help why it like this
It is working but your ImageView take all the width and it don't have android:src attribute (so it show nothing) and you don't need the last LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/saldo"
android:orientation="vertical">
<!-- Useless Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch#gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

How place overlay imageview on two layouts?

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

Android, Layout: How do I get my button to overlay existing layout in axml?

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>

Android - EditText isn't filling up available space in a fragment?

I'm having an issue with my EditText (with id of body) not filling up the available space in my layout. I've been searching everywhere and experimenting with numerous resources, but I just simply can not seem to get it and have been spending hours on literally just this.. I'm guessing there is an issue with how my entire layout is set up, and probably can't just make a tweak in EditText. By the way this layout is being used in a fragment, maybe that changes things? I'm not sure, what do you guys think? Thanks for any and all help! Here is 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:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="write those saucy lyrics"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I'm looking for my design to look like this (taken from my graphical layout editor):
However on my device it looks like this(snapshot from my device):
Try this..
Change android:layout_height="wrap_content" to android:layout_height="0dp"
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
// try this way,hope this will help you...
<?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">
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/title"/>
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/body"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
Make
android:layout_height="match_parent"
instead of
android:layout_height="wrap_content"
in Body edit text
So that it becomes
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:scrollbars="vertical" />
UPDATE:
Plz try following layout
<!-- Put the buttons at the bottom -->
<RelativeLayout
android:id="#+id/rel_lay_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Confirm" />
<Button
android:id="#+id/btnEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:alpha="1"
android:text="Emial" />
</RelativeLayout>
<!-- Put the title layout at the top of parent -->
<LinearLayout
android:id="#+id/lin_lay_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<!-- Occupy rest of the space of screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_above="#id/rel_lay_btn"
android:layout_below="#id/lin_lay_title">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:layout_weight="1"
android:scrollbars="vertical" />
</LinearLayout>

Categories

Resources