<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dip"
android:background="#drawable/greybox"
>
<ImageView
android:id="#+id/profile_pic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/profile_pic">
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Kumar"
android:textSize="18dp"
android:textColor="#4c3f38"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/msg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_below="#+id/name"
android:textColor="#7b7674"
/>
<LinearLayout
android:id="#+id/picpostlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="5dp"
android:layout_below="#+id/msg"
android:orientation="vertical" >
<ImageView
android:id="#+id/picpost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#null" />
</LinearLayout>
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/picpostlayout"
android:layout_alignParentRight="true"
android:textColor="#000000"
/>
</RelativeLayout>
</RelativeLayout>
Here is my complete xml.I am using the linearlayout to show the posted picture,but it is still showing very small size.I used two relative layouts, one for complete xml and another for name,message,postpicture.
Here is also my screenshot to the above given xml file.I am getting the large image but I cant able to show the same size,it is showing very small size.
I got an post picture from facebook api,I am getting very large image as I used _n.jpg,but when I tried to display using imageview it is showing very small size.
][1]
[1]: http://i.stack.imgur.com/63nTO.png
Here is the code of getting posted picture from facebook api.If the post object has picture field then I get that picture and changed that into large image and I added that to my ArrayList pic.
if(jsonObject.has("picture"))
{
String fetchedURL = jsonObject.getString("picture");
String getFeedPicture = fetchedURL.replaceAll("_s.jpg", "_n.jpg");
pic.add(getFeedPicture);
}
Then I send that ArrayList to my Adapter where I set that image to imageview by sending to imageloader class.
Here is my loader class reference imageloader and I am setting image to imageview.I am setting this in my adapter class.
imageLoader.DisplayImage(postimage.get(position).replace(" ", "%20"), postimg) ;
Make this modification to your current code:
String fetchedURL = JOFeeds.getString("picture");
String getFeedPicture = fetchedURL.replaceAll("_s.jpg", "_n.jpg");
pic.add(getFeedPicture);
This is the simplest way to get a better quality picture from your Feeds. The whole point of this piece of code is that by default, the Facebook API returns a small version of the image. By replacing the _s.jpg with _n.jpg gives you a bigger image.
I use this code throughout my application and it works like a charm every single time.
And the corresponding code for this is:
<LinearLayout
android:id="#+id/linlaFeedPicture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_margin="1dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgvwFeedPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#null" />
</LinearLayout>
Related
I have a list view and at runtime I add a header to it with a header_layout as below.
<RelativeLayout
android:id="#+id/alertslayoutheader"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_gravity="center"
android:scaleType="centerCrop"
android:src="#drawable/dash_vector_alpha2"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:gravity="center_vertical"
android:padding="40dp"
>
<TextView
android:id="#+id/text360"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:fontFamily="sans-serif-normal"
android:gravity="center_horizontal"
android:singleLine="false"
android:text=" 360°"
android:textColor="#ffffff"
android:textSize="38dp"
android:textStyle="normal"
/>
</LinearLayout>
Using an ImageView, I place a picture in centere of the header. I am able to achieve this. But then(as expected I guess) the image gets cuts-off below header and does not show up bottom parts in rows below.
I want it to not get cut off by rows below. I want the header image to fill rest of rows below. The image in header also needs to scroll.
Using a padding + setting it as background for whole listview doesn't help as resolutions vary.
appreciate any help.
Thanks
So I'm trying to get used to Android and intending to create an app for the NASA's "Image of the Day" RSS feed, which essentially needs an image- and a couple of text views.
This is my current attempt at the layout (compiling for Android 4.3, if that should matter):
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.headfirst.nasaiodt.Feed" >
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:contentDescription="#string/testImgDescription"
android:src="#drawable/test_img" />
<TextView
android:id="#+id/titleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testTitle" />
<TextView
android:id="#+id/dateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testDate" />
<TextView
android:id="#+id/descriptionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testContent" />
</LinearLayout>
You'd think that's simple enough for its purposes, however, I just can't seem to get rid of a very resistant white bar on the right side of the picture:
Wasn't
android:layout_width="match_parent"
in the ImageView supposed to take care of that?
(And no, it's not an eclipse glitch, it also shows up in the emulator.)
I'd appreciate your help. What am I doing wrong?
Try using scale type to fit X and Y coordinates. This will solve if its not a glitch.
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:contentDescription="#string/testImgDescription"
android:src="#drawable/test_img" />
The answer may be staring right at me but I just can't see it!
Am getting a null pointer exception when setting the text on a Textview with a string from a ArrayList of Strings. Have initialised everything and checked the ArrayLiist has data, everything seems to check out. But when the textview is been declared in onCreate() I can see in the debugger the value remains null.
OnCreate():
private TextView title;
//onCreate()
setContentView(R.layout.gallery);
imageNames = new ArrayList<String>();
title = (TextView) this.findViewById(R.id.tv_imageDescriptionGallery);
setImageAndTitleArrays();
//check size of arrays and build correctly
Log.d("GALLERY VIEW:" , "IMaegNaem array Size: "+imageNames.size() + " Image Array Size: "+ bitmapArray.size());
Log.d("GALLERYVIEW: ", "First Image Name of Array: "+ imageNames.get(0));
//set default image title and description, we will update every tome a image clicked
//exception throne here as title=null on debugger
title.setText(imageNames.get(0));
The textview :
<TextView
android:id="#+id/tv_imageDescriptionGallery"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Image Name"
android:textColor="#55bbfa"
/>....
Gallery XML
<?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="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/background2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astro Gallery"
android:textColor="#55bbfa"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Gallery
android:id="#+id/gallery1"
android:layout_marginTop="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/splitter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sample_note"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/splitter" />
<ImageView
android:id="#+id/imageView1"
android:layout_marginTop="100dp"
android:layout_width="420dp"
android:layout_gravity="center_horizontal"
android:layout_height="350dp"
android:src="#drawable/camera1" />
<TextView
android:id="#+id/tv_imageDescriptionGallery"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Image Name"
android:textColor="#55bbfa"
/>
<Button
android:id="#+id/send"
android:layout_marginTop="10dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Set Wallpaper"
android:background="#drawable/button_bg"
android:textColor="#fff" />
<ImageView
android:id="#+id/shadow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#drawable/shadow" />
</LinearLayout>
</ScrollView>
Only 2 hypothesis :
Maybe you tried to import R.java and you imported the wrong one ?
Or try to remove "this" in front of findViewById?
The 2 only ideas that come to mind, hope it can help.
Although I checked all the imports, removed all the ref to 'this, rename the class and all refs to it, cleaned and build, could not resolve the NPE.
I deleted the class and xml from the project, then made a new class and xml file with same code and worked fine.
I had a class with exact same name in a separate project, not sure if this has anything to do with it.
I'm new to Android development and I'm trying to achieve a layout for my app that is capable of handling different screen resolutions/ratios.
I've been reading a lot of the documentation and questions on this site to try to understand the basics and concepts.
First I went through:
developer.android.com/guide/practices/screens_support.html
And questions like:
stackoverflow.com/questions/6403619/how-to-support-all-the-different-resolutions-of-android-products
I've got a pretty basic idea on how to handle things out. But still, its pretty difficult for a starter to get going, and I found myself stucked trying to achieve the solution I came up with.
I designed my app to a target resolution of 480x800, and set it up to always show in portrait mode.
This is how it looks like and how I understand it should work (I used Waldo for the sake of example haha):
(sorry for the link, I need 10 rep to post images)
http://i.imgur.com/KXTAXir.jpg
My root Layout is a LinearLayout, wich contains 3 other Layouts being A and C set up to a weight of 0.8 while B is at 8.4. This is all fine, but the contents of B are set up to DP units at the moment just to be able to test.
B consists of a frame Layout who has 3 other Layouts inside, where 2 of them are working fine, and shown only when needed. The problem is that I need B to be able to adapt based on the contents of it first child: a LinearLayout wich contains 2 ImageView and 1 ProgressBar. I need that those ImageView always keep their ratio.
Here is an example of how it should work:
http://i.imgur.com/cH7fUze.jpg
Imagine those 4 are real screens, wich vary in ratio and size. So my app should only adapt B (from my first image) to keep the images original ratio.
Here is the layout code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/darkgray"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:background="#666666" >
<TextView
android:id="#+id/level_text_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="LEVEL"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/level_text_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="SCORE"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/level_text_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="01:59"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8.4" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="1000"
android:progress="0" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true" />
</LinearLayout>
<RelativeLayout
android:id="#+id/pauseMask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:visibility="gone" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/gameoverMask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:visibility="gone" >
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:background="#666666" >
<TextView
android:id="#+id/level_text_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="0/0"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Button"
android:onClick="useHint" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/button1"
android:layout_centerVertical="true"
android:text="Button"
android:onClick="toggleSound" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/button2"
android:layout_centerVertical="true"
android:text="Button"
android:onClick="togglePause" />
</RelativeLayout>
The last thing that stays unclear to me is how to handle the text and button sizes. Should I set them in DPs? How do I get them to scale accordingly like it can be seen on the bottom of my second picture.
Thank you for your help, I also want this to serve as an example to others that are having trouble to understand how to handle this kind of scenarios.
I'm not sure, if I got your question right.
However, you can specify different layouts for different screen sizes and orientations, as described here: http://developer.android.com/guide/practices/screens_support.html
Just give the respective suffix in the name of your layout XML file.
I ended up creating a custom View for my images. The view calculates the space thats left on its parent, scales the images manually and then resizes itself to the same size of the resulting image.
To resize the progress bar to have the same width as the images, I used a custom listener that gets triggered when my custom views get resized. Then I resize the progressbar to match their width.
With this I achieved what I wanted, a layout that will work perfectly in all screen sizes.
In my android app i want to design a layout exactly like twitter layout with a Image and Text View.
See the following screenshot
Please help me with this. How can i design this layout ?
Update:
Forget about background images and top bar. I am requiring 6 images and textviews. In the below image twobirds with Tweets(167), Lists, Mentions, Retweets etc.,
What you want is fairly simple, tho I am sure there are more fancy way's of doing this then i'm
about to show you.
For my application I used 4 ImageButtons, but the principle is the same for 4 or 6 buttons.
This is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/actionbar_layout"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="#drawable/actionbar_background"
android:gravity="center_vertical">
<TextView
android:id="#+id/tekst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App name"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:layout_marginLeft="5dp"
android:textStyle="bold"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/button_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#id/actionbar_layout">
<ImageButton
android:id="#+id/button_schedule"
android:src="#drawable/schedule_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:background="#FFFFFF"
/>
<TextView
android:id="#+id/text_schedule"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="Rooster"
android:textSize="20dp"
android:layout_below="#id/button_schedule"
android:gravity="center"
/>
<ImageButton
android:id="#+id/button_locations"
android:src="#drawable/locations_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:layout_below="#id/text_schedule"
/>
<TextView
android:id="#+id/text_locations"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="Links"
android:textSize="20dp"
android:layout_below="#id/button_locations"
android:gravity="center"
/>
<ImageButton
android:id="#+id/button_rss"
android:src="#drawable/rss_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:background="#FFFFFF"
android:layout_toRightOf="#id/button_schedule"
android:layout_alignParentRight="true"
/>
<TextView
android:id="#+id/text_rss"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="RSS"
android:textSize="20dp"
android:layout_toRightOf="#id/text_schedule"
android:layout_below="#id/button_rss"
android:layout_alignParentRight="true"
android:gravity="center"
/>
<ImageButton
android:id="#+id/button_settings"
android:src="#drawable/settings_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:layout_toRightOf="#id/text_locations"
android:layout_below="#id/text_schedule"
android:layout_alignParentRight="true"
/>
<TextView
android:id="#+id/text_settings"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="Instellingen"
android:textSize="20dp"
android:layout_toRightOf="#id/text_locations"
android:layout_below="#id/button_settings"
android:layout_alignParentRight="true"
android:gravity="center"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/twitter_layout"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_below="#id/button_layout">
<Gallery android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/gallery"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">
</Gallery>
</RelativeLayout>
I pasted the whole file, so you can see how I implemented my actionbar.
But what you need is the second RelativeLayout tag.
You align your buttons/textviews by using "android:layout_toRightOf" and "android:layout_below" attributes.
Your first button is simple, the second one (the one to its right) you align with "android:layout_toRightOf="#id/first_button"
A third button (below the first button) can be aligned using "android:layout_below="#id/first_button"
The same goes for textviews, just use layout_toRightOf and layout_below to align them. The attributes only apply to the RelativeLayout.
Hope this will help you out a bit.
What you want to do is called a Dashboard pattern.
You can find implementation of ActionBar and Dashboard patterns in sources of the Google IO app. ActionBar in the file actionbar.xml (and HomeActivity.java, ActivityHelper.java), Dashboard in the file fragment_dashboard.xml (and DashBoard.java).
im sure , it's can be created like this :
image and textView mustBe on layout - so :
//start "a" code
LinearLayout oneObject ;
oneObject= new LinearLayout(this);
//need set to vertical mode
oneObject.setOrientation(LinearLayout.VERTICAL);
//it's our one object . image+text
next : TextView text = new TextView(this);
text.setText("tweets"); // or get from array
///image it's can be what you want - button, layout, textView(-____-)
// just need set on background new image . iget button - for normal clicking ;//
ImageButton image = new ImageButton(this);
image.setImageResource(r.drawable.blabla)
oneObject.addView(image);
oneObject.addView(text);
//also u need create 2 columns and add to this columns our object
//for size of oneObject - use LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(curWidth/2,curHeight/6); curWidth and curHeight - its my resolution of screen.
//end "a" code
for creating 6 objects u must rung it in cycle :
all code = "a"; so
for(int i = 0;i<6;i++)
{
a/// where a all our code
}
Hope it's help you.. also i can put more code where need some fixings