I have used this code to get a feed reader form twitter. I have list them in the listView as the article says, but with some images I have a problem with the size and they are anormally big...I have tried unsuccesfully to fix the size of the image with:
<ImageView android:id="#+id/photoUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="10dp" android:maxHeight="10dp"
android:paddingRight="12dp"/>
Strange that the code didn't do that for me when I wrote it. What android version are you testing on?
For one reason or another, I've found that often only specifying maxWidth/maxHeight doesn't behave as you would expect, and I also have to specify minWidth/minHeight to effectively control image size. I had to do exactly that in a follow-up development tutorial to the post you reference.
Give something like this a try:
<ImageView
android:id="#+id/photoUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="30dip"
android:minWidth="30dip"
android:maxHeight="30dip"
android:minHeight="30dip"
android:paddingRight="12dip" />
Related
So I have been working on an Android application to make an application for use with DJI's consumer level drones. I have been making the user interface and using XML throughout the project with no issues. I want to add a .png to the UI just so that my logo is showing. When I preview it in Android Studio, I can see the logo being shown but when it is run on the tablet, it is not there. Everything else using XML is fine though. I even preview using the same resolution/ screen size as my tablet I am using (cheap Hudl 2 tablet).
If anybody has any ideas about how I can get this to work, I would appreciate it. I have shown my university lecturer it and he couldn't give me an answer too as nothing seems to be out of the ordinary.
Android studio preview
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/macrosfordji"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
Try this (android:src="..." instead app:srcCompat="..."):
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/macrosfordji"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
After 2 days of fruitless testing, I've decided to post my issue here, in the hopes that I'm missing something obvious.
I've boiled down a seemingly innocuous xml-layout to a random collection of images, layouts, and a scrollview. Here it is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:background="#drawable/wood_texture"
tools:context="com.testlayout.example.testlayout.MainActivity">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/image_one"
android:id="#+id/imageOne"
android:adjustViewBounds="true"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<ImageView
android:layout_width="300dp"
android:layout_height="150dp"
android:background="#drawable/dark_wood_texture"
android:id="#+id/darkWood"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"/>
<HorizontalScrollView
android:layout_width="300dp"
android:layout_height="150dp"
android:id="#+id/handScrollView"
android:scrollbars="none"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/handLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/image_three"
android:id="#+id/imageView"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/image_three"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/image_three"
android:id="#+id/imageView6"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/imageTwo"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="#drawable/image_two_tiled"
android:scaleType="fitXY"/>
</RelativeLayout>
I can load this layout onto my phone just fine, but after swiping around in the scrollview for as little as 5 seconds, the app will suddenly crash to the home screen - without reporting that the app has stopped working. I've been testing on a Samsung Galaxy s6.
I've also tested this on a Samsung Galaxy Tab 2, where this problem does not occur (both my real app and this test app run just fine on the tablet).
I've created a new Android Studio project; the only changes I've made are to the res/layout/activity_main.xml, as outlined above. I've also included the drawables I'm using. I'm hoping someone with better debugging skills than I can either pull down that project, or simply create a new one of their own using the above layout (that's all there is to it, though you'll need my drawables regardless).
I'd like to clarify that I'm not looking for a way to fix this issue, I'm trying to understand the issue. The thing is, after 2 days of testing, I've found half a dozen ways to seemingly "fix" the issue. But none of them make any sense, and they all seem unrelated. If I don't know why my solution fixes the issue, I won't know how to avoid it during future development.
Observations
As I mentioned above, I've found several ways to "fix" the issue (i.e. make it no longer crash), but none of them seem to be related. Here are a few:
Set the visibility of almost any of the elements to gone.
Remove the background from the root element.
Remove the line android:tileMode="repeat" from drawable/image_two_tiled.xml
Note that changing the tileMode to something else - for instance, clamp - does not fix the issue. Only removing it (or setting it to disabled).
Set the src of the ImageView with the id "#+id/imageTwo" to image_two_smaller_tiled.
This is the exact same image as image_two_tiled, just a smaller resolution.
This is by no means an exhaustive list of, but it gives you an idea of how disjointed these fixes are (especially the tileMode one).
As near as I can tell, it looks like some kind of memory issue. I'm fairly new to android development, so I'm not quite familiar with the memory constraints I need to work with, but I would be horrifically concerned if I was causing the heap to explode with so few images, and of fairly small size (at the very least, certainly not big).
If anyone could tell me exactly what is causing my app to crash, I would be. . . Well, I would be extremely grateful. 'Cause after 2 days of trying to debug this myself, I'm about ready to quit android development : (
Edit
The app itself does not throw an exception, however logcat does consistently show this error at the time of the crash when I'm not filtering log messages from my app alone.
E/Resources: RunTimeException
android.content.res.Resources$NotFoundException: Resource ID #0x7f0202cf
at android.content.res.Resources.getValue(Resources.java:2558)
at android.content.res.Resources.startRC(Resources.java:1116)
at android.app.ActivityThread$mRunnable.run(ActivityThread.java:3056)
at java.lang.Thread.run(Thread.java:818)
e2: I'm starting to wonder if this is an issue with my phone, and not the app, since I can run it just fine on my tablet. I'd really like to know if anyone else is experiencing this issue if they try to run this on their Galaxy s6. Specifically the S6 - that would tell me if it's an issue with my phone or all S6's in general.
This previous SO post answer solved my issue.
In short, it was the BitmapDrawable that was causing the entire issue. While unfortunately I cannot say why this fixes the issue, setting the view that uses the bitmap with layerType="software" will prevent the crashes.
In a layout: android:layerType="software"
In code: view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
I have an Android layout xml file here:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/locationMarker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/locationMarkertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner_map"
android:gravity="center"
android:minWidth="180dp"
android:onClick="create"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="Pick the Location"
android:textColor="#android:color/white" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:onClick="create"
android:src="#drawable/plus" />
</LinearLayout>
This xml layout renders to look like this:
This works fine for android but I want to use this xml layout on the iOS app as well. I was wondering if there was a way to convert this xml layout to a svg or png format or anything that would allow me to re-use this item without needing to re-create it. It needs to have transparency and a .svg would most likely be better than a .png if that works. I would like only the displayed visible part to be clickable if possible.
The equivalent technology in iOS is Apple's "autolayout" system.
It's quite easy to use once you get the hang of it; the fact is though like anything it's a specialist thing. And sure, you could just make a transparent PNG and use that as an image for a UIButton.
I would really suggest just using a "UIButton" in Apple, and play with the colors etc until you get a look that is OK -- although not identical to the other platform.
The two key points are
it's almost impossible, technically, to make apps look identical on different platforms
pretty much everyone agrees you should not try to do that; other than in games, allow elements like buttons etc. to be "natural" on each platform / os version.
BTW I have no idea why anyone would downvote your question. Cross-platform issues are one of the most critical in development today.
So I received a graphic interface for an application I'm building. It has some images and texts and the images are set in a specific way, and some text goes inside or on top some images.
In the android project I opened I get the default activity which is RelativeLayout, but it's hard to set all the elements exactly where they should be with the designer and editing the XML directly seems like a pain.
I also see that elements that I add always "align" to something or right/left to some other element - but what I really want to do is place them at a specific location (so the end result will be the same as the design I got). If I was building it for the web I would have used absolute positions.
What is the correct way to go about this in android?
Thanks
EDIT
I managed to start implementing some elements of the design in a manner that makes them look ok on the eclipse Graphical Layout and on my device.
Is this XML ok - or am I using it wrong:
<ImageView
android:id="#+id/imgClouds"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/layout_activity_main_imgClouds"
android:scaleType="centerCrop"
android:src="#drawable/clouds_ltr" />
<ImageView
android:id="#+id/imgBaby"
android:layout_below="#+id/imgClouds"
android:layout_width="50dp"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="75dp"
android:contentDescription="#string/layout_activity_main_imgBaby"
android:src="#drawable/baby" />
<ImageView
android:id="#+id/imgBubble"
android:layout_toLeftOf="#+id/imgBaby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_marginLeft="56dp"
android:layout_marginTop="-5dp"
android:layout_marginRight="5dp"
android:src="#drawable/bubble_ltr" />
</RelativeLayout>
This is primarily opinion based, but there's certain things most android developers will agree, "Absolute Position" is not an option in Android, because of the OS Nature like Fragmentation in Device Screen Sizes/Densities, having an absolute position of the elements will lead to a crappy app, it will look good only in the device you are using and chances are that all the other devices will not look as you expect, you really need to look at the android design patterns and best practices to avoid a terrible GUI implementation, RelativeLayout is the best way to go, in android you must learn to love it...
Also the sooner you get used to work with XML directly in layouts will be better for you, most IDEs that help out with this functionality end up adding a lot of unnecessary code, once you go through the learning curve to build layouts using XML it totally worth it.
Hope it helps!
Regards!
I'm trying to make an Android layout like the one below. I have a couple of questions:
1 - what is the element called that FB uses for posts? Ie, it doesn't look like a text view, but the element looks like it separates each post with a divider line. Also, the text style is different for a person's name and how long ago they posted. I'm looking to duplicate this (minus pictures) but I can't find the right UI elements.
What is the element called at the bottom? It's like a static menu. IE, it's the same as a menu but instead of pressing "menu" to access it, it's on the page at all times.
Finally, are there good tutorials/examples on how to make nice looking, professional layouts like the apps on the market? The tutorials that I've found on layouts are really basic. I'd like to understand what elements exist, what all of the attributes mean and see examples, etc. So far I'm only able to see the capabilities from other applications. I'd like to have a handbook or some type of some type of reference manual to go to.
For the "fancy" text views you can make a linear layout that hosts a <RelativeLayout>:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0">
<ImageView
android:id="#+id/userPhoto"
android:layout_height="64dip"
android:layout_width="64dip"
/>
<TextView
android:id="#+id/userFullName"
android:layout_height="25dp"
android:layout_width="fill_parent"
android:layout_marginLeft="70dp"
/>
</RelativeLayout>
Once you have a relative layout you can add different views inside of that to create a sort of customeized view.
As far as good examples I would look at this book. It's easy to understand and very helpful on such things.
I found a really helpful tutorial to solve a problem in ListView Row design a bit like yours. It goes a bit further explaining how to do Async Image loading but the first part should help you.
Also, I might be wrong (I am still a bit new to this) but I think the answer above lacks a TextView for the actual message besides the userName and the relative positions of the elements since it is a relative layout. Something like:
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/userPhoto"
android:layout_toRightOf="#id/userPhoto"
android:textSize="17dp"
android:textStyle="bold" />
<!-- actual message -->
<TextView
android:id="#+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/userName"
android:layout_marginTop="1dip"
android:layout_toRightOf="#id/userPhoto"
android:textSize="15dp" />
The key in organizing a relative layout is:
android:layout_alignTop="#id/userPhoto"
android:layout_toRightOf="#id/userPhoto"
and
android:layout_below="#id/userName"
android:layout_toRightOf="#id/userPhoto"
I might be wrong but if it helps, great! Just adding my bit to the other answer.
Cheers