I am trying to add a custom border to a framelayout. The framelayout is used as container for the fragment. Thus I want to display fragment with a border. The border should be external to framelayout and should not consume the space inside of framelayout. And it should adjust with change in screen size.
What i can think right now is some sort of custom ViewGroup, add ImageView for border. Use image processing to get the inside area of imageview and in that area inflate a frame layout.
I am looking for some easy way out.
The easiest solution for this would be to create a 9-patch drawable and set it as the background for your FrameLayout. I have created the below 9-patch drawable that you can use. Hope this suffice your requirement.
You can obtain the effect via layout XML using for example LinearLayouts with proper layout_weight, so your centre-most FrameLayout will expand to take up available space.
There are 4 drawables used: for top, bottom, left and right part of frame.
Check out this code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/border_left" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/border_top" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- FrameLayout content goes here -->
</FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/border_top" />
</LinearLayout>
<ImageView
android:layout_width="wrap_conttXY"
android:layout_height="match_parght"
android:scaleType="fient"
android:src="#drwable/border_right" />
</LinearLayout>
Related
I have an cup shape image.
i want to change my relative layout exactly same as my imageview,
is it possible in android?
Any help?
Thanks
Change layout like this image
Imageview
Use ImageView in RelativeLayout set imageview to
imageView.bringToFront();
Hope this helps :
<RelativeLayout
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#id/rel_actionbar"
android:layout_margin="10dp"
android:padding="4dp">
<RelativeLayout
android:id="#+id/rel_screenshot"
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="#+id/img_to_print"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<ImageView
android:id="#+id/img_tshape"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#drawable/img_t"
android:visibility="visible" />
</RelativeLayout>
Set imgTShape.bringToFront(); In java file As Milan Suggested and use Transparent image for this.
Use relScreenShot.addView(imgPrint, 0); to add view dynamically inside the layout and set image in imgprint that will remain inside the root layout only.
For what purpose do you want your layout like to be so?
In one word, it's impossible.
Android View must be Rectangle shaped although they can store non-rectangle shape images inside.
I have needed to create view like and this view will be placed like
I am trying to create this using frame layout but finish with failure. How can i do this?
Either use a FrameLayout and add this as an imageview last with specified right and top layout margins for this view and some slightly larger right margins for the underlying layout.
Or a RelativeLayout and you align this view to the parent right using (layout_alignParentRight="true") and with margins as with previous example.
Example trying to mimic your layout a bit, tweak the margins and image to your needs:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bbbb00"
android:layout_marginRight="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#888899"
android:layout_margin="20dp">
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="80dp"
android:src="#drawable/test"/>
</FrameLayout>
I have this LinearLayout that is going to be placed on the bottom of an activity layout. I want this LinearLayout to have a 4dp elevation, just like the top toolbar should have, however, since android:elevation places the shadow below the ui component and this specific component (linearLayout) is going to be on the bottom of the screen, I won't see any elevation at all..
This is my LinearLayout code, and an image of it with the default elevation implemented:
<?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="wrap_content"
android:weightSum="3"
android:background="#android:color/transparent"
android:orientation="horizontal"
android:elevation="4dp"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/playButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/bottom_toolbar_menu_selector"
android:src="#drawable/ic_play"
style="?android:attr/borderlessButtonStyle" />
<ImageButton
android:id="#+id/stopButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/bottom_toolbar_menu_selector"
android:src="#drawable/ic_stop"
style="?android:attr/borderlessButtonStyle" />
<ImageButton
android:id="#+id/bookmarkButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/bottom_toolbar_menu_selector"
android:src="#drawable/ic_bookmark"
style="?android:attr/borderlessButtonStyle" />
</LinearLayout>
Is there a way, using elevation to place a shadow on top of the ui component?
Thanks in advance!
You can't theoretically do it with android:elevation, in the sense that you can't choose the direction where the shadow is going to be cast.
There are two solutions.
1. Drawables
You could, for instance, put an ImageView right above your layout and set android:src="#drawable/shadow". This should be a vertical GradientDrawable defined in XML, as explained here.
2. Workaround
While most of the shadow is actually below the view, a subtle shadow is also above. A workaround might be using a very high value for elevation, like 40dp: the bottom part is going to be hidden due to your layout, while the top is going to be expanded and look like a common shadow.
In either case, you do not have control over the elevation value in dp, in the sense that you can't be sure your shadow is equivalent to the one cast by android:elevation=4dp.
use like as;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="205dp"
android:background="#color/white"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="-5dp"
android:background="#color/white"
android:elevation="3dp"
android:paddingTop="5dp">
// CHILD VIEWS
</RelativeLayout>
</LinearLayout>
Add this code above of view in which you want top elevation or add android:layout_marginTop="-4dp" and add below of above view
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0.01dp"
android:layout_below="#+id/scrollbar"
app:cardBackgroundColor="#android:color/transparent"
app:cardCornerRadius="0dp"
app:cardElevation="#dimen/dp_4" />
Try this i am unable to set background through xml then i tried the programmatic way to solve that and i work perfectly refer this if facing problem on show shadow in Linear Layout
lprofile.setBackgroundResource(R.drawable.background_with_shadow);
lprofile is my ref of Linear layout and background_with_shadow is xml for applying shadow i hope i will for ur requirmement...thank u..
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.
I want to do this efect:
The last linear layout contains a circle in an ImageView and the background is set from the center to the end, how can I do this?
Using a shape doesn't work fine..
You can either use a stretched image as background, or have multiple layers of views.
In the latter way you can have a RelativeLayout, a background view, and the foreground view:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="48dp">
<View
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:background="#808080" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
text="This is the foreground" />
</RelativeLayout>