Android hide a view partially behind screen - android

Hello I am working with android.I have a custom imageview.I want to hide partial imageview behind the screen. I tried padding=-100... etc. But its not working .How can I hide a view partially behind screen ?

use negative margin to parent layout like this, its working
<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:layout_marginTop="-20dp"** >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
</RelativeLayout>

You need to create your view through java or make a drawable of semicircle and set it as background of imageview.
Refer this: Semicircle drawable

Related

How to scroll layout with adjustPan

I have a nestedscrollview in my fragment which is having button below of nestedscrollview, when keyboard arrives button moves above of the keyboard and the entire layout handle its scrolling properly but the issue is with the background image which get shrink.
I've used android:windowSoftInputMode="stateAlwaysHidden|adjustResize" in my Manifest file and if i use adjustPan then view does not scroll entire layout shift up.
I know this question is asked so many times but I didn't found proper answer.
Please Help.
Follow steps like below :
After that you are able to achieve what you want:(Below code is MainActivity.xml code)In this code Image View is your background image.
<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:background="#color/colorAppBack"
tools:context=".activities.LoginActivity">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/login_image_min_2" />
</ScrollView>
// Your container layout which contains fragments like framelayout or what ever you are using
</RelativeLayout>
In manifest:
android:windowSoftInputMode="adjustResize"
Your image is shrinking because you have added image inside scroll view too.
Try to add image out side the scroll view as image is background image.
This way Image wont scroll.

How do i keep image on transparent background?

I want to acheive the following. Transparent background with white tick
How do i get the white tick mark on the transparent background.
i tried the following.
viewprev = mgridview.getChildAt(i - mgridview.getFirstVisiblePosition());
viewprev.setBackgroundColor(Color.WHITE);
viewprev.setAlpha(0.5f);
Try this out,
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<ImageView
android:id="#+id/ivMain"
android:layout_width="200dp"
android:layout_height="200dp"
android:contentDescription="#string/app_name"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#99676767"
app:layout_constraintBottom_toBottomOf="#id/ivMain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/ivMain">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:contentDescription="#string/app_name"
android:src="#drawable/vector_favorite" />
</FrameLayout>
Your tick should be in the FrameLayout which should be constrainted as in the code so its always in the middle of the ImageView. From the image I guess you're trying to create a long click to select items kind of thing. If so just set the visibility of FrameLayout to gone in xml and in LongClick event set it to visible
This is the output of above code:
You can play around with the color to achieve your desired transparency level
You may need to use FrameLayout.The Framelayout contains your image and an empty ImageView above it. When you need to draw a tick - just set its image into that ImageView.
First you need to add an ImageView to your grid item layout. Remember to insert the xml tag below the main grid image in order to appear on top. Then use match_parent as the image view width and height and assign the scaleType to center. This is your check mark view. You can add a semi transparent background to make a shade above the grid item image and the src attribute goes to the check mark.
You can also modify the image view visibility toggle hide and show of the check mark item.

Android transparent toolbar over an ImageView

I'm trying to have a transparent toolbar,
such that it will be shown on top of an ImageView which is set as follow:
<ImageView
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="8"
android:scaleType="center"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:elevation="0dp"
/>
Illustration (blue area is an ImageView):
so, it is transparent, but it pushes the ImageView down, instead of being on top of it.
I also tried using android:elevation, but it didn't help.
Use frame layout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
// Your imageview
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
//your toolbar
</FrameLayout>
This should help
Toolbar is just ViewGroup. So consider making layout like Relative layout.
In Relative layout, u have such order : the lower position in layout code, then this view would be considered as highest layer of layout. So put your views in correct order and you will achieve desired result. Worked for me many times before.

Android - Background at bottom

I should like to have an android app which has its background image on the bottom of the view.
Hopefully this could be achieved by only using XML.
My background image (bg.png) is located at the folder "res/drawable-mdpi".
The XML code is now:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg"
android:layout_alignParentBottom="true"
android:layout_marginBottom="0dip" />
</LinearLayout>
But this is stretching the whole image over the whole page. I only want it stretched in horizontal direction.
The height has to be in proportion with the (stretched) width.
And this image has to be the background of a view/layout, I want to keep using the layout and add items/objects to it.
I hope someone could help me with this, I've been looking on the internet for it for a few hours and I couldn't find anything more helpful then I have now.
Thanks in advance,
Dennis
Firstly Change your LinearLayout to a RelativeLayout (android:layout_alignParentBottom only works with RelativeLayout).
Secondly use android:src="#drawable/bg" on your ImageView (not background)
if you really want to use the LinearLayout, you can try adding this attribute to your imageview android:layout_gravity="bottom"

Why is my Android list item background image displaying with a dark overlay?

This is my Android list_item layout XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="?android:attr/scrollbarSize"
android:background="#drawable/list_bg">
<TextView
android:id="#+id/tv_displayname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
This is the list_bg image:
and yet here is what it looks like when shown in Android emulator:
I can see that the background is being applied because there is a slight gradient effect to it, but I have no idea where this black overlay is coming from!
have you tried a different image to see if that one does the same thing? to me it looks like it is creating the image behind the list in your RelativeLayout and your textview background is on top. since you are setting it to fill the width of the row, i bet if you just set to wrap_content you would see it behind there
try putting the image as your TextView background instead

Categories

Resources