How can I attach this triangle with cardview in Android? - android

is there any specific component in Android or I have to use view to make triangle (showing in round in image) and attach to card but still as I uploaded image it would not be as same as in image.

Well there are many approaches , but mine is :
You will create an Image like that in photoshop (Of course measure it well and Target all devices (dp)), then place it inside your drawable folder , and call it on top of your CardView.
Suppose that image is called image_traingle.jpg you can do it this way
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:onClick="Contract"
android:layout_margin="10dp"
app:cardCornerRadius="7dp"
android:layout_height="90dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Imageview
android:layout_width="wrap_content"
android:gravity="left"
android:background="#color/colorPrimary"
android:src="drawable/image_triangle"
android:layout_height="match_parent" />
.
.
.
</LinearLayout>
</android.support.v7.widget.CardView>

Related

ImageView vertically centred in MaterialCardView

Objective: I am trying to make a MaterialCard with an Image inside it, as well as some text below the Image. This current layout will serve as a "menu" for the application, where the user can select where to navigate to.
Problem: The ImageView is appearing vertically centred in the MaterialCardView. I would like the ImageView to "stick" to the top of the MaterialCardView. There are large sections of MaterialCardView above and below the ImageView.
My XML Code:
<ScrollView
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="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true"
android:id="#+id/appBar">
<Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/design_default_color_primary_dark"
app:layout_scrollFlags="enterAlways">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/application_title"
android:textColor="#color/colorWhite"
android:textSize="24sp"/>
</Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="#+id/mealPlannerCardView"
android:contextClickable="true"
android:focusable="true"
app:cardBackgroundColor="#color/colorWhite">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:src="#drawable/wedding_dinner"
android:contentDescription="#string/wedding_background_cont_desc"/>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="#string/mealPlannerTextView"
android:textColor="#color/design_default_color_primary_dark"/>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</ScrollView>
output
I tried to use layout_gravity="Top" but it made no difference.
EDIT
android:scaleType="fitStart" made the Image "stick" to the TOP of the MaterialCardView, but now very large space beneath the ImageView that requires scrolling to get to end.
Add the line below in your xml
android:layout_gravity="start|top"
See if this repositions the image for you. Worry about centring later if this works.
You might get the result you want by setting a scaleType for the image view.
Checkout this link: https://thoughtbot.com/blog/android-imageview-scaletype-a-visual-guide
It shows examples of each scaleType, it will help you to choose the right one to achieve the appearance you need.
This is happening because the Android framework is trying to maintain the aspect ratio in the face of your height and width constraints and default scale type.
There are more than one solutions to your problem and its for you to choose based on whose results are acceptable to you. All these solutions revolve around helping the framework with ImageView's aspect ratio. Let me try to put down the possible solutions that I can think of.
First solution can be as simple as changing the scale type on your ImageView as below:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="#drawable/wedding_dinner"/>
That will take away the white spaces but crop your image.
A slight variation of the above, where you can define a fixed height of the image. This is a surprisingly widely used solution as it provides a certain
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="centerCrop"
android:src="#drawable/wedding_dinner"/>
Finally, a more elegant and better solution is to provide a fixed aspect ratio to your images using a ConstrainLayout.

Rectangular frame with transparency for camera

I'm working on Android app with custom camera module. Main purpose of custom camera module is in adding overlay to camera - it should be something like outer transparent border (see first attached pic). It's actually blurred in the attached picture, but I need at least transparent effect as blur is not trivial to implement on Android.
The main point here is to ensure that "clear" visible area is corresponding to A4 format, so height divided by width should be √2 (main purpose of the app is in taking photos of A4 sheets).
I've figured how to achieve "inverted" effect - see second picture. But I can't get my head around on how could setup the view for the desired effect - first picture. Could someone share their thoughts on the problem? Here is the code:
camera.xml:
<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="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4">
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:id="#+id/overlay"
android:layout_width="316dp"
android:layout_height="446dp"
android:layout_centerInParent="true"
android:background="#drawable/overlay"
android:duplicateParentState="false" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:background="#android:color/black">
<Button
android:id="#+id/button_capture"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#drawable/capture_button"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button_close"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_centerVertical="true"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:layout_toLeftOf="#+id/button_capture"
android:background="#drawable/close" />
</RelativeLayout>
</LinearLayout>
overlay.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/listview_background_shape">
<solid android:color="#88ffffff" />
I've found an article about just like what I needed. With little effort I could adjust the code there to get desired effect: https://blog.budiharso.info/2016/01/09/Create-hole-in-android-view/
To avoid tricky vector masks, it's enough to define the id/overlay as layout with 4 semitransparent rectangles, sharing the same drawable you use now: top, bottom, left, and right. You can determine the dimensions of each rectangle at runtime, but if you like intellectual challenges, you can define them as a ConstraintLayout.

how to change relative layout shape similar to image in android

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.

how to make single view with multiple imageviews?

how to make single view with multiple imageviews?
I know this is just a simple question but its puzzle for me ...
problem
there are 4 images one for whole background image ,2nd is transparent heart and 3 image is to put in heart and 4 image is a shadow image of heart but how to manage these four images in a single view(any layout)....
Any help would be appreciated see link to see my desired output
link to see photo
update
<RelativeLayout
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/hv_effect"
android:layout_below="#+id/effect_hedaer_toolbar"
android:background="#drawable/home_wall"
android:weightSum="1">
<FrameLayout
android:id="#+id/relative_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center|center_vertical"
android:padding="50dp">
<ImageView
android:id="#+id/iv_effect_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ImageView
android:id="#+id/iv_effect_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_vertical"
android:adjustViewBounds="false"
android:scaleType="fitXY"
android:src="#drawable/pip" />
</FrameLayout>
</RelativeLayout>
i have used relative for background image and framelayout to show two imageview to show one is for to show lamp image and second two move as background (user selected image)....
problem:
problem is user selected image must be move only inside lamp.
update read comments to get answer
I'm pretty sure you can do it simply by using a RelativeLayout. The transparent image should be the last one in the layout, example:
<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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/background_image"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/transparent_image"/>
</RelativeLayout>

Android image display full height - loaded asynchronously

Hey I begin my adventure with Android and I can't solve one problem.
I am loading pictures from web server using Universal Image Loader. I put them into Relative Layouts which is located in ListView. The effect that I want to achieve, is that pictures are displayed on the entire screen with full width and height with a small box at the bottom.
In the IDE preview, everything looks ok:
But on my phone loaded images look like that. I want them to be displayed with full height. It is necessary to use programming functions to achive it?
Loading images:
imageLoader.displayImage(
wallpapers.get(position).getSrcUrl()//the drawable
, currentWallpaperViewHolder.imageViewWallpaper//the image view
, imageLoaderOptions);//the display options
return itemView;
List view:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:id="#+id/WallpapersListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Image view:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/wallpaper_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/test"
/>
<TextView
android:id="#+id/wallpaper_date_for_use"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textStyle="bold"
android:text="Date of use" />
</RelativeLayout>
It's probably because you have a RelativeLayout as your root view. Try wrapping the outside RelativeLayout in a LinearLayout.
You can do this,
Get the device height.
And then set imageView height programatically as the device height.

Categories

Resources