Android : How to make TextView with compound bitmap - android

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

Related

Custom ImageView With a Custom Shape

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.

How to get drawable divider between Grid View Rows?

i want to know if there is any way to display a drawable file in between the grid view rows ?(only rows) I want to get the layout in the following way
i used grid view to display books and i have divider in drawable folder and i need to show it in the that way
i searched a lot but every thing just says how to give color divider between rows but i need to display the divider from drawable
is there any way to do it?
You can define custom divider, check code snippet below:
<GridView android:layout_width="wrap_content"
android:divider="#drawable/divider"
android:dividerHeight="3sp"
android:layout_height="wrap_content" />
where divider is your custom drawable image. You can also check this link for more clarification:
custom divider

How to make each row of android listview a trapezium instead of ractangle?

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);

Add draggable shape on a picture in Android

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>

Android: How to Create a Custom button widget

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.

Categories

Resources