Background image doesn't fill Linearlayout and changes that size
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#mipmap/dashboard_background"
android:orientation="vertical"
android:padding="10dp">
desirable look is this
How can I reach that?
You should use a frame layout with an imageview and a linearlayout inside
<FrameLayout
android:id="#+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/background"/>
<LinearLayout
---Your Layout---
</LinearLayout>
Background always stretches to its View size. So you can't really control how it will look like. Instead, put an ImageView as a bottom most (meaning that it will lay under everything else) element in your layout, and use your background image as a source (src) for this ImageView, and so you will be able to control the look of the background with scaleType (probable you would want to use centerCrop or fitCenter). More about scaleType here.
In the end your layout should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#mipmap/dashboard_background" />
<FrameLayout
android:id="#+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put your view elements here -->
</FrameLayout>
</FrameLayout>
Related
I tried to do many things: set alpha value, set background:transparency, set backgroud different colors like "#90000000", I even created another view with transparency above my reciclerView. But I always have one result:
(do not look at white pictures, I will set them later)
And I need transparency like that one:
So as you see image and line are not under transparency. Do you have any ideas how fix it?
I think you declare the RecyclerView in the front of root,
if you are using a RelativeLayout like a main View in the xml layout, you have to make sur that your transparent View below your RecyclerView, this is an example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent">
</RecyclerView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9A000000">
</FrameLayout>
you can define two image view and first set the background your image and for secondly set the other background.but you must set the same size.
You can show a overlay above this recyclerview. Just like this.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55000000"
android:translationZ="100dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
LinearLayout works as overlay
I have a CoordinatorLayout, in where a RecyclerView displays some CardViews, defined in an other layout. Under this scrollable view, i am trying to add a RelativeLayout, which inherits fields for text input, buttons for sending it, etc.
The problem: CoordinatorLayout seems to block the whole screen, although i told to wrap contents height. Nevertheless, RelativeLayout is added (tested it by setting Coordinator-height = 50dp), but off-screen. What is wrong here?
PS: I know how to solve it with android:layout_weight=xx. But thats not what i want to achieve, because it blocks my EditText to expand, if bigger texts are entered.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/data_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.CoordinatorLayout>
<RelativeLayout
android:id="#+id/delete_data_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#id/data_coordinator_layout">
<EditText/>
<Button/>
<Button/>
<Button/>
</RelativeLayout>
</RelativeLayout>
It's actually pretty simple. You need to align your Relative Layout (delete_data_layout) to bottom of your parent. Then you make the Coordinator layout above the Relative Layout. This causes, that Coordinator layout will always stay above the Relative Layout - even when the Edittext expands.
Here's the XML.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/data_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/delete_data_layout"> <---- Change here
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
<RelativeLayout
android:id="#+id/delete_data_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"> <---- Change here
<EditText/>
<Button/>
<Button/>
<Button/>
</RelativeLayout>
</RelativeLayout>
I want to use an image which is smaller than width of the screen, but has height bigger than the screen. I was thinking to use scroll view, that the whole image could be used, but fitting changes original ratio of the picture. How can I make it to adjust width and increase height by the same ratio? Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/tutorial"
>
<ScrollView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/tutorial">
</ImageView>
</ScrollView>
</LinearLayout>
you don't use fill_parent you want use match_parent
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backround="#drawable/tutorial"/>
use android:scaleType="CENTER_INSIDE" in Your Imageview thats it.
for more details
read more about CENTER_INSIDE here
I am using following configuration to properly fit image inside a scrollview.
<?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"
android:scrollbars="vertical" >
<ImageView
android:id="#+id/textNimbo"
android:layout_width="match_parent"
android:layout_height="2492dp"
android:layout_alignParentRight="true"
android:src="#drawable/inicio"
android:adjustViewBounds="true" />
</ScrollView>
However I need to set also a button inside scrollView and below the ImageView. I tried relative and linear layouts inside scrollView but no succes, button is not visible or image doesn't fit to scrollView. Any recommended configuration? Thank you.
A ScrollView can only have one direct child element. So to add a Button and an ImageView, you'll need something like this:
<?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"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android"layout_height="fill_parent">
<ImageView
android:id="#+id/textNimbo"
android:layout_width="match_parent"
android:layout_height="2492dp"
android:layout_alignParentRight="true"
android:src="#drawable/inicio"
android:adjustViewBounds="true" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
You could also use ImageButton I
instead of a ImageView with a transparent Button on it
I would like an imagview that takes up the width of the screen (or layout) but there seems to be padding around the view that prevents me from doing this.
With the corresponding xml:
<?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" android:weightSum="1">
<ImageView android:src="#drawable/icon" android:background="#null"
android:layout_height="106dp" android:id="#+id/imageView1"
android:layout_weight="0.59" android:layout_width="match_parent"></ImageView>
</LinearLayout>
The padding is come from transparent area on android icon.
Just remove unused transparent area or use another image.
Try changing:
android:layout_width="match_parent"
to:
android:layout_width="fill_parent"
make layout width and height as fill_parent
<ImageView android:src="#drawable/icon" android:background="#null"
android:layout_height="fill_parent" android:id="#+id/imageView1"
android:layout_weight="1" android:layout_width="fill_parent"></ImageView>