I have on a project the following Image defined in the Layout-Main:
<ImageView
android:id="#+id/imageViewCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/compass"/>
This Image View represents a compass and I would like to add over the image an indication showing the Direction to follow.
Actually the image rotates to indicate the North direction
You can make images for each of the directions and change them according to your needs in the MainActivity.
Related
I want to blur the text of a TextView, but the text is cut off left and right.
Image of the cut off text
I tried to increase padding, margin. Changed gravity, Enabled/disabled font padding. Set a fixed height, lowered font size etc. All to the same result: The sides were cut off.
The setting of the mask filter is just two lines:
textView.paint.maskFilter = BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL)
textView.postInvalidate()
This is how my XML layout looks like:
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-1dp"
android:includeFontPadding="false"
android:layerType="software"
android:textSize="48sp"
tools:textColor="#color/solid_white"
tools:text="132" />
I'm looking for a solution to see the text fully without cutoffs on the edges.
Remove this attribute from your <TextView> tag:
android:layerType="software"
Hardware acceleration is required for views to draw outside of their bounds. Note that padding doesn't help here because view contents are clipped by padding as well.
After attempting a ton of alternatives, using a LeadingMarginSpan.Standard(margin) to offset the text did the trick. I overrode the class and added the blur mask there rather than using a MaskFilterSpan.
I am working on an App which shows images (by capturing using camera or choose from gallery) in some activity. The problem I am facing is showing images of different sizes. The actual size of image is very big even those which are captured by camera of same phone are large in size. So if I show them in an ImageView the get stretched.
I have seen in some apps like Facebook, when image is displayed in Full Screen mode, it maintains the aspect ratio I guess. The whole image, whatever its size may be, is shown in the screen but it doesn't get stretched. The image automatically adjusts its height and width as per the need. How to achieve the same functionality?
How to make ImageView which would be able to adjust its height and width (maximum already defined) as per the need.
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="matrix"
android:src="#drawable/defaultimage"
android:padding="10dp" />
You need a different android:scaleType in your layout. The ImageView.ScaleType documentation lists the different ones that are available. It sounds like you probably want to change matrix to fitCenter in your example.
I have created a 6x7 board for a connect 4 game.
All the empty cells are image buttons.
When in portrait mode the board looks like this.
However, when I change orientation to landscape it looks like this.
The layout for one of the empty cells (Which I repeat) is
<ImageView
android:id="#+id/r6c4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/arrow4"
android:layout_centerHorizontal="true"
android:contentDescription="#string/emptyBox"
android:src="#drawable/empty"
android:visibility="gone"/>
I am very new to android, can anyone point out how I may be able to resize the images to fit the landscape screen?
Thanks
Is there a way for me to tile an image along the right side of an activity view? The image i have is small and square.
i know you can tile the entire activity view like this:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/actual_pattern_image"
android:tileMode="repeat" />
but is there a way to restrain it? to make it just tile one image under the other along the right side?
i know i can do something like this:
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
and just keep increasing the margin as i add another imageView below. my only fear with this approach is when scoll-bars come into picture. this is clearly a very static approach...
just a heads up - very new to android development...
If you know the width of your tile, you can create a bitMap whose width is the width of your tile, and whose height is the height of the full view. Then place this view on the right side of your activity view.
It would be easiest if your view had a relative layout that filled your view, and you had your bitmap align with the the right of the relative layout like this:
android:layout_alignParentRight="true"
How can I prevent my bitmap from being scaled automatically in an ImageView or ImageButton if the view or button is stretched using "fill_parent" or using "weight"?
This will be useful, for example, to create a 4-button toolbar at the top of the screen where the buttons are equally spaced, but the images inside the buttons keep getting streched even if I use scaleType="center", which should prevent scaling according to the doc, but it doesn't.
Any insight is appreciated!
Thanks,
I have found that when using android:background automatically scales the image you are using there to the size of the View.
I tried using the android:src to put the image in the view. The image did not scale, but I could not get the image to center relative to the size of the View.
So I tried making the whole Button it's own relative layout and this is what I used:
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageButton android:id="#+id/ImageButton01"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageButton>
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/cardback1"
android:layout_centerInParent="true"></ImageView>
</RelativeLayout>
The ImageButton is in the background and will always be the same size as the layout.
The ImageView however will always stay centered in the RelativeLayout and will not scale.
This way the RelativeLayout itself can grow and move and the Image on top of the button will always stay the same size, but the button will grow. The image will however shrink if the Layout becomes smaller than the image itself.
I think that's what you were looking for. There may be a better way to do this, but this is all I can come up with right now.
Simply modify your drawable, apply a larger transparent background. Say my drawable in hdpi is 41*48 px icon.png . I created a new image 60*60 px with a transparent background , copy-paste the previous icon.png and save under the same name. This way you don't need to touch your layouts .
Then you can check the button zone larger if you apply a non transparent android:background:
<ImageButton android:id="#+id/widget_open"
android:src="#drawable/icon_widget_arrow_up"
android:background="#ff777777"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageButton>
Apply the previous and new drawable to android:src , you should clearly see ImageButton area.
By the way, I am running the app in compatibility mode.
If the image is scaled, make sure you are not running your app in compatibility mode (for instance if you target Android 1.5/1.6 without supporting multiple densities and you run the app on Android 2.0.)