Consider the image above.
The red lines indicate the image file borders, the black lines indicate the actual "useful" pixels of the image, and the white = transparent.
How would I go about getting these images positioned this way?
I'm not really sure this would make a difference in the way the above is done, but I am planning on implementing basic animations to each image (make each image rotate in respect to their respective centers).
This is what I have so far (positioning the 3 elements in the center, overlapping each other):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<ImageView
android:id="#+id/img_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription = "#string/img1"
android:src="#drawable/img1"
<ImageView
android:id="#+id/img_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/img2"
android:rotation="45"
android:src="#drawable/img2" />
<ImageView
android:id="#+id/img_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/img3"
android:rotation="200"
android:src="#drawable/img3" />
Thanks!
/e 1 - Thank you for editing in the image
2 - I solved this problem through trial and error, thank you anyways!
Related
I have an image with a textview on top of it. I am wondering how I can blur the background of my textview (only part of the image) to make it more readable. I have tried looking at the Blurry library but it seems like it can only blur the whole picture.
Add this custom BlurView solution: https://github.com/mmin18/RealtimeBlurView
Then put your BlurView positioned behind the TextView in your layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<com.github.mmin18.widget.RealtimeBlurView
android:id="#+id/textview_blurview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/my_textview"
android:layout_alignBottom="#+id/my_textview"
android:layout_alignStart="#+id/my_textview"
android:layout_alignLeft="#+id/my_textview"
android:layout_alignEnd="#+id/my_textview"
android:layout_alignRight="#+id/my_textview"/>
<TextView
android:id="#+id/my_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text in front of blur view"/>
</RelativeLayout>
Finally, set the blur and color as desired in code
blurView.setBlurRadius(80.0f);
blurView.setOverlayColor(R.color.background_blur_color);
You can use frame layout to produce a blur effect , frame layout allows to align views along z-axis the last child appears above all other children, example of usage:-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="200dp"/>
<TextView
android:layout_width="match_parent"
android:background="#10000000"
android:layout_gravity="bottom"
android:layout_height="100dp" />
<TextView
android:layout_width="wrap_content"
android:text="Text Here"
android:layout_marginBottom="50dp"
android:layout_gravity="bottom|center_horizontal"
android:layout_height="wrap_content" />
</FrameLayout>
You can also set the textview background to some color (#AARRGGBB) with lower aplha (AA < "FF" ->max alpha) to reproduce a similar effect easily.
As you want to make your textview more readable as it sits over the imageview. To do this instead of blurring image why don't you use gradient drawable or color.
I had same requirement in my app and I simply went with placing grading view over the part of ImageView.
Let's do this
Step 1: Create a gradient shape and put it under drawable folder, let say shape name is gradient_overlay.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="#00000000"
android:startColor="#BB000000"/>
</shape>
Step 2: Create a dummy view and place this over the ImageView or part of ImageView.
<View
android:id="+#id/gradientView"
android:layout_width="match_parent"
android:layout_height="60dp" // adjust the height
android:layout_alignBottom="#id/picture" // give the id of your image
android:background="#drawable/gradient_overlay">
</View>
Step 3: Then align your textview over the gradientView. so that text become proper visible.
I am Using a imageview under framelayout . I applied a background image in image view but image cannot fully cover the screen. it appears in center. I want to fully cover the Screen ...
How can i achieve it?
Thanx in advance :-)
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"
tools:context="com.example.muhammad.maqalatlayout.jild_copy"
android:background="#color/Green">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#mipmap/brown_border1"
android:layout_margin="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_gravity="top|left|bottom|center_vertical|right"
android:visibility="visible"
android:adjustViewBounds="false"
android:scaleType="fitStart"/>
My Current output is like this.
I believe your scale isn't working because you are setting the android:background property. Try this:
<ImageView
...
android:src="#mipmap/brown_border1"
... />
Also, preferably put your image in the /drawable/ folder.
use
android:scaleType="fitXY" and `match_parent` instead of `fill_parent`.
I am absolutly a beginner in Android development and I have some problem positioning an image into an ImageView element of my layout. So I have the following situation, I have this fragment layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Dummy content. -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="0dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:scaleType="fitCenter"
android:layout_height="350dp"
android:src="#drawable/carbonara"/>
<!--android:background="#drawable/carbonara" />-->
<TextView android:id="#android:id/text1"
style="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
</LinearLayout>
</ScrollView>
So, as you can see in the previous code snippet I am setting a background image into an ImageView having an height of 350dp setted.
The problem is that the image height is less that 350dp and this is what I am obtaining:
As you can see in the previous screenshot what I obtain is that I have the 350dp ImageView (highlighted in blue) and the image is setted inside it vertically centered. I don't want that the setted image is vertically centerd but I want that it start at the top of the ImageView.
How can I implement this behavior? What am I missing?
I have tryed to change:
android:src="#drawable/carbonara"/>
with:
android:background="#drawable/carbonara" />
and in this way it fills all the ImageView space but in this way the image could appear deformed so I think that it is not a good solution.
try to change in your layout and test again.
android:scaleType="fitCenter"
to
android:scaleType="fitStart"
See full docs here
I have a long vertical image (224x1600). I want it to fit the image width, and scroll vertically. It needs to be scroll-able. I have tried everything and can't get it to work :\
Here is what I have
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android1:id="#+id/tab3"
android1:layout_width="fill_parent"
android1:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/tiles" />
</LinearLayout>
</ScrollView>
Second question is: Is there a way to PREVENT image scaling? The image is 224x1632 and shows that way on my galaxy nexus. On the Nexus 7 (much larger screen but lower DP) it goes to 199x1440. A weird scaling of 88%. Can I prevent this? I need it to display 224x1632 on all machines and scale the width accordingly.
Many thanks!
If you need to avoid scaling entirely, you should place your drawables in the res/drawable-nodpi folder. Keep in mind that the physical size will be much different on devices of different densities, but as long as you understand the risks, that is the solution you should pursue.
On your first question, I'm inclined to think you'll need to do some manual work in code, but although I can't test it right now, this also might work:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/tiles"
/>
</ScrollView>
Give it a shot and let me know how it goes.
It should work... I think the problem is that you have android1: and it is suppose to be android:
Something like:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/tiles" />
</LinearLayout>
</ScrollView>
As for the second question, you can try and use android:minWidth="" and android:minHeight="" to see if that solves your problem.
EDIT: try android:scaleType="fitCenter" it will display the image as is.
Hope that helps.
I can't find a topic talking about my problem which seems to me standard ... And that make me think it is not possible. But I give a try.
I have a RelativeLayout with a 9 patch background (which contain a content area).
Is that possible to center horizontally and/or vertically a TextView inside this RelativeLayout in relation to the content area ?
this layout file will do the task
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:gravity="center" >
<TextView
android:id="#+id/txtTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test TextView"
android:textColor="#000000" >
</TextView>
</RelativeLayout>
the 9-patch image i used is