I am trying to create a custom ImageView that Shows images inside a custom border and shape instead of default rectangle, and out Side of The Borders are TransParent.
my border is an SVG File, How I can do this? thanks
Use this library siyamed/android-shape-imageview or create a custom view that extend from View class and override methods!
But the easiest way is using this library
create a bitmap that you want to mask your original picture and use this like below :
<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="8dp"
app:siShape="#drawable/octogon" <!--mask bitmap-->
android:src="#drawable/neo" <!-- original bitmap -->
app:siSquare="true"/>
Extend the Image View class and change it according to your use. Not just Image View you can customized any view class you just need to extend parent class.
Related
I need to insert vertical bar inside an element list.
The vertical bar must be change color in according to the type of element,
is that possible?
I show this in the image:
Yes, it is possible.
The easiest way to do it would be to simple add a View with a background color in your row layout.
Something like this would achieve the desired behavior:
XML layout
<View
android:id="#+id/color_bar"
android:layout_width="16dp"
android:layout_height="match_parent" />
In Kotlin (perhaps a RecyclerView adapter):
val colorBar = findViewById(R.id.color_bar)
val color = ContextCompat.getColor(context, R.color.your_color_here)
colorBar.setBackgroundColor(color)
You can also use a cardview and edit its background in the drawable folder
I want to customize my listview to achieve this design,are there any library available for this?what can be best way to achieve this.Are there any disadvantage with such designs.
Thanks,
You can achieve this in two different ways
add an image instead of divider containing these tilt lines you can do this by using a simple line of code in your layout or in your class
android:divider="#drawable/divider_image"
or you can change it in you java class like this
list.setDivider(R.drawable.divider_image);
the second way of achieving this is you set a static image in you item layout below the item and change it according to your need as if the item is odd set a different image and if the item is even set a different image
<ImageView
android:id="#+id/imageViewDivider"
android:src="#drawable/divider_image"
android:scaleType="fitXY" />
and change the image in java class
ImageView imageView = (ImageView) findViewById(R.id.imageViewDivider);
imageView.setImageResource(R.drawable.divider_image);
i want to create a TextView with compound Bitmap, i know android support creating TextView with compound drawables but i want to compound Bitmap as i downloaded images online
note : i don't want to make LinearLayout holds imageview and textview
Here's how to do it in XML code. This adds a Drawable at the top. You can change it to left, right or bottom:
<TextView
android:id="#+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/yourdrawable"
/>
Edit
Sorry, totally misread your question. You can do this in code by creating a BitmapDrawable and then using that as a compound Drawable. More info here: http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html
Can anyone explain how can I add shape (for example a rectangle or an arrow) on to a image (in ImageView)? Once added, the shape will need to be draggable to anywhere in the image. And finally need to save the image edited (with the shape on top of that).
What informations do you really need?
This can be some steps to do:
Maybe create a new object to handle this:
Create a new class and extend from ImageView or use LayerDrawable for that.
Write setters/getters for the main-background-image/bitmap.
Add your own Vector shape (create a new class with definable color,thickness... or hard-code it)
Do all of your drawings in onDraw-Methods
Implement onTouch interfaces to handle your selection and dragging.
Create new method (render to jpeg/png/..) to save your resulting image
Create a Custom view from View that completely overlaps your ImageView. This view will have a transparent background and contain the draggging view. Initially set visibility to invisible.
In Custom view class override the onTouch event where you update the dragging views margins.
On save, get drawing cache of the parent layout(that contains both the ImageView and Custom view) and use as needed.
Sample xml code:
Relative layout parent whose drawing cache has to be grabbed using rel.getDrawingCache()
<RelativeLayout .......>
<ImageView ......./>
<CustomView ......./>
</RelativeLayout>
I would like to create a button with circular or rectangular background, text and an image below or above the text.
Here is the CustomButton Layout where I added the objects (background and text - ImageView is missing):
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal">
I would like to create a CustomButton object with methods setText() and setImage() which would change the button text and image and place multiple CustomButtons into main layout.
Does anyone know how to create a custom layout, place it into another layout(main) and modify its elements from the activity which is bound to main layout?
I would really appreciate your help.
Thanks!
Hey, To create a circular button or rectangular button you can use shape.
It can be done in .xml file.
see this Click Here
If you want programmatic access, you should subclass View and do your work there in java. You can still do the layout in xml, but have the image and text methods that you want. You will then be able to use this in another layout to place your CustomButtons.