How to display the image inside the android widget background? - android

I have a widget layout xml which sets the src to the delivered android widget 4x1 frame image.Here is the widget layout code.
<?xml version="1.0" encoding="utf-8" ?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tuwidget" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="#+id/tuwidget_img_btn"
android:src="#drawable/widgetinitial"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</AbsoluteLayout>
#drawable/widgetinitial holds the widgetinitial.png image example 4x1 at developer.android.com (AppWidget design guidelines).(4x1_Widget_Frame_Portrait.psd) What I am trying to do is display an image inside the delivered frame instead what happens is the frame image goes away and only the image I am trying to display shows up. How can I display the image inside the bounding box or the background?
Any help is much appreciated.
Another question - I think I saw in a couple of forums AbsoluteLayout is a deprecated feature for Android 2.1 and above. Is that correct? and does using AbsoluteLayout throws any force close or other exceptions?

AbsoluteLayout is deprecated. It doesn't throw any exceptions, but its generally a bad idea to use it because it is really hard to design a layout that will work on all screen sizes. There is generally a better way to do it using a different layout.
In your case, I don't follow exactly, but it sounds like you want to layer two widgets on top of each other? An image with a frame? To do so, I'd use a FrameLayout. This is designed for having multiple layers of images.
Common layout objects is also a good guide to the basic layout types.

Take a look at the end of the page 2 of this pdf

Related

Slanted Imageview or Shape in Android

Hello i would love to implement a slanted / sloped imageview or layout in android like the one used in the Yahoo news digest App.
Here is a screenshot of what am trying to achieve
Yahoo news digest App http://imageshack.com/a/img673/921/yDLbs2.png
Thanks
there are 2 things to watch care fully
triangle shape is fix in every layout so you have to take image of that just having that type of triangle and other side is transparent
thing u have to visualize that tringle area also contains the type of news like (4) US news then you have to take frame layout in which having 2 things
Image (triangle shapped)
TextView (or the layout that shows like (4) US News)
and rest of the part is in linear layout.
now your confused that how that image going to place?
i also have that ans
take this example
<ImageView
src="image"
width="fill_parent"
height="#dimen/responsive_mesured_height"/>
<scrollView
fillviewport="true">
<LinearLayout
`orientation="vertical">
<LinearLayout
width="fill_parent"
height="#dimen/responsive_mesured_height"
background="#android:color/transperent"/>
<LinearLayout>
<!--rest of content-->
</LinearLayout>
</LinearLayout>
</LinearLayout>
</scrollview>
still if u don't believe me then go for news digest apk and download it and extract it.
after that go for mdpi-v4 folder in res folder there u find morning_triangle_background.png for light theme.
and for dark theme evening_triangle_background.png
now above code is for that image paralex effect you will feel that content are scrolling above that image just like website.
where #dimen/responsive_mesured_height is the hight of imageview (if you want to make responsive then define diff heights in all different folders like values,values-sw600dp,values-sw720dp,values-large(to support lover then 3.2) etc.
i hope this description helps all.

Android Studio Google Map V2 fragment rendering

I tried to write a test demo for Google Map V2 in Android Studio. I followed every step from Androidhive Google Map V2 or better I think I need.
I'm using the same layout_main.xml
<?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" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
but I'm getting always the same rendering problem:
Rendering Problems
A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
I have absolutely no idea what's the problem. Did I forget something?
I just need to add Google services in the build.gradle like
compile 'com.google.android.gms:play-services:4.4.52'
I copied the manifest from the demo and changed the API Key.
The accepted answer is not wrong but it does not help.
As Dan wrote, Android Studio (also Version 1.0) will not display the map.
Maps needs an API key and dynamic processed code, maybe some day we will have that but so far not.
I've a 5 minute solution for those who want to see their app properly in layout preview:
To properly develop I still needed something else than a blank background.
I added overlays and buttons on top of the map, I really needed to see the map while placing elements over it.
The solution is simple:
1. Make a screenshot of your app with the map running (Power + Volume Down)
2. Download the screenshot and use an image editor to remove the top and bottom UI elements, so you will end up with only the map itself as an image.
3. Import that image into android studio drawables
4. create a new layout, name it dummy_mapviewfragment, put only a linearlayout and an imageview in
5. make the imageview "fill" the parent, and set "src" to the cropped image you just imported
6. back to your layout, add this into your Mapview Fragment xml :
tools:layout="#layout/dummy_mapviewfragment"/>
That's it, now you will have a non-interactive mapview fragment which displays a real map.
Your app will look like it looks on your mobile phone.
If you made errors in your image cropping you can "fix" it by setting the image scale to "centerCrop" so it will properly stretch out.
Update: You can get a screenshot without need to crop directly from within Androidstudio! Makes it a bit more convenient ;)
Rendering Problems
A tag <fragment> allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
This is just the preview window telling you that it can't display a preview for the <Fragment.../> tag, because it doesn't know what kind of fragment you're going to put in it. You can safely ignore that message - your actual app will render the fragment fine when you run it (as long as you code it up correctly!).
Android Studio automatically offers a solution within the error description, which is adding the name of the fragment layout.
tools:layout="#layout/fragment_my"
Add a dummy layout "#android:layout/simple_gallery_item" as:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="317dp"
android:layout_height="385dp"
android:id="#+id/map"
tools:context="com.example.XYZ.googlemaps.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="#android:layout/simple_gallery_item"/>

Animated Splash Screen in android

Hi all I'm trying to figure out how to implement a animated splash screen in android application like Appy Geek application. I tried to use a gif animated pic but it is not animating in android.Then I used android Drawable Animation. Form Drawable Animation I'm able to create a animation but to do that I need sequence pictures (Frame by Frame). I need to know is there any other techniques in android to do this.
Traditional animation isn't great because you need a bunch of pictures. You can use property animation either via xml or java.
http://developer.android.com/guide/topics/graphics/prop-animation.html
anim.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="50%"
android:animation="#anim/slide_top_to_bottom" />
and set these to main layout::->
android:layoutAnimation="#+anim/anim"

iOS to Android: How to display a TextView

I have a background in iPhone development, which may be a cause of some of my confusion with Android, which I am very new at developing.
My question is this: How to I create two TextViews, and specify their exact location on screen? For example, on the iPhone, I would create a UILabel, generate a rectangular frame that specified the label's size and position, and then set this rectangle to the frame property of the UILabel.
If you can help me understand the similarities with Objective C and iOS' UILabel, that would be most helpful.
On Android, we don't use absolute screen positions. This is highly discouraged. It's pretty understandable that you think this way if you are coming from iOS. But you need to revise your habits.
Instead of absolute positions, we use layouts, such as LinearLayout, RelativeLayout or FrameLayout. All of these allow you to arrange your views dynamically. And in many cases, it will automagically adapt to the screen size, which vary a lot from device to device.
Actually, there's nothing exotic about dynamic layouts. Many major UI toolkits, such as GTK, or Qt, work similarly. Pixel position are a bad idea in my opinion, except maybe in the Apple world, where the OS and the hardware are tightly coupled, but this is an exception actually.
So, in your case, all that you need is to put your text views into the appropriate layout. Please read the documentation and tutorials about the different types of layouts mentioned above to decide which one is best. The question is how you want your views to be placed relatively to each other.
Create a basic Android project in eclipse. You will be having a main.xml layout file in your project. You can open it in Eclipse using Ctrl+Shift+r and keying in main.xml
copy paste this in your xml after clearing its content.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:text="TextView One"
android:layout_height="fill_parent"
android:layout_weight="1"></TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:text="TextView Two"
android:layout_height="fill_parent"
android:layout_weight="1"></TextView>
</LinearLayout>

Design view problem in xml file : Android

When I run my application, buttons are not displaying(A little part is displaying, that makes feel that something is there), although I scroll down.
How to solve my problem. Is there any way to set size of textboxes (Where size depends on screen size).
Pankaj did you checked the orientation of the root LinearLayout tag ??
All you need to do is change root LinearLayout's orientation to vertical & you will see every button in your layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
& please read more about layouts before implementing them.
As #100rabh already said you should really start reading about Android layouts.
Some very good articles by Romain Guy are here and of course on his blog.
There is also a very good series of articles on Mobiletuts+ called Android User Interface Design by Lauren Darcey and Shane Conder.
You should really check that out and then redesign your layout.
As you're using linear layouts, you can use android:layout_weight. If you search, you'll find many examples.

Categories

Resources