When I drag a gridview into the graphical layout screen in Android Eclipse, and give it wrap content, then it fills the height of the screen with 24 placeholders.
How can I limit its length? Note this is fine when I actually run the application because my adapter adds 6 items and it isn't very long. I simple want a way of telling eclipse that in an absence of real data that it should draw something with say 6 placeholder items
I don't think it's possible to set the number of items just for the aesthetic purposes of the graphical view in xml builder. If you must do it, you could set the height to look acceptable in the XML via a literal value such as 100dp, then set the layout params for height to Wrap Content when you assign and initialize it in your onCreate(). That way, it will look the height you require in the graphical interface editor, but will wrap the number of elements you add to it when it's running on the device.
http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html
I agree this is not the most elegant solution, but it would probably work.
Related
Which is the best option to create a responsive layout design? The first question is what should be the height and width of every view (it should be in percentage, match constraint or wrap content using constraint layout).
If we use wrap content I think there is no way to create a responsive design with help of wrap content because if content increase the view will take all the space of the screen either vertically or horizontally
If we use match constraint then, in that case, it's good, but sometimes it is looking awesome on Android Studio but when we run it on a real device it doesn't look the same
The last option is to use percentage, in that case, I think first we have to check our item list vertically and horizontally and provide them space according to their content priority and usage
So what will be the best case to create a responsive layout in XML for Android?
It depends on UI.generaly people use the 2nd and 3rd methods because by using constraints and percentages you can get responsive UI.
sometimes it depends on your requirement.
if you are using the percentage method and you set the imageView at 10 % it's looking proper on your device but sometimes it happened that in a small device that imageView is not looked proper
So the moral is all your three methods can be applied as per UI you can not make all designs responsive using 1 method
I'm an Android newbie. I have an app whose main screen uses an ExpandableListView with only 5 rows. Is it possible to stretch these rows so that they fill the whole screen? Currently only half the screen is occupied and there is a large empty space.
I have tried match_parent, wrap_content for the list's vertical height but nothing helps. Please assist.
Changing the height attribute on the list does not help because it only tells the listview how much screen space it may occupy.
The individual items your list is displaying are not affected by this, as they will still follow their own layout rules on how to use available space in the listview.
To solve your issue, you might want to look into extending BaseExpandableListAdapter. You can define a custom layout for the listview items, in your case you'd probably just make the item views a bit bigger so they take up more space. You'll find detailed tutorials on how to do this all over the net.
However, using this approach (with a static list size of 5 items), you'll eventually run into the same issue again on devices with larger screens. Your custom list may now look like you want it to on a 4" smartphone, but have a large empty area on a 10" tablet device.
Depending on what purpose you are using the list for, you might want to rethink your UI design approach.
I've one of the simplest layouts imaginable: A num pad.
I want to create a fragment containing a 3 x 4 grid of buttons. The layout should automatically resize the num pad to fill the available space.
I've learned, that GridLayout is not up to the task, and TableLayout/TableRow or nesting LinearLayouts means nesting weights, which is also discouraged for performance reasons. A RelativeLayout won't work either, because that requires at least one button with given dimensions.
So, is there a clean way to create a regular grid that will resize to fill its parent?
Any help is appreciated, thx!
You will need a custom compound control.
Check the following link:
http://developer.android.com/guide/topics/ui/custom-components.html#compound
Make the control fill the available space. Make it to have 12 buttons. Calculate the size and position of them based on their position and the available space.
Depending on your needs you might also need to override onMeasure() and onLayout() defined earlier in the above document, in the "Fully Customized Components" section.
for practice I am writing an activity that takes a string from a local DB and puts it into a listView. However the string's are of different length, ranging from a couple of characters, to a couple of sentences. Write now I can take them and place them in a listView but, not all of the strings fit. I was curious if/how you can dynamically choose the height of each part of the list view so that the entire string can fit in it.
Just make sure your list item layout is using wrap_content for its layout_height attribute. If you're using a fixed height, it won't scale to fit larger strings. If you want the lists a specific size except for in situations as mentioned, you can also add a android:minHeight attribute as well with the dimension you want as standard.
Also, make sure your TextView is set to multiline (attribute android:singleLine="false").
I am struggling with a Layout Problem on Android. This is very simple to do on the iPhone, but with the various screen sizes and the Layout classes available. I am having a hard time doing this.
One thing that I have noticed is that setting backgrounds on objects in the xml really messes up the layout on the device. I generally have to put in a FrameLayout and an ImageView to get a background.
So Am trying to get to this. http://www.calidadsystems.com/images/AndroidListItem.png (Sorry I don't have enough pts to post the image)
his is a status view and is an item in a List View. There are 8 TextViews that need to be set. Each of the 222 fields will change. The current background has the colors in there at specific locations and I am trying to line up the Labels and TextViews to get the picture below. I built this one with AbsoluteLayout which is deprecated, but it also does not work very well on the device.
I have constantly struggled with the layouts on Android. Does someone have some good sample code that could do this?
You're probably going to want to use a RelativeLayout. You can use the android:layout_alignTop="id" attribute to make the rows be in line correctly. And android:layout_alignLeft="id" for the columns. Other than that its just a matter of playing with the android:layout_marginLeft="XXdip" attribute to get the space between them how you want it. Check out this page for an overview and examples of all of the Layout types. Here is some more sample RelativeLayout code. And one more page with another example. RelativeLayout is a bit tricky to get used to but once you've used it a few times its pretty easy to understand and get the Layout that you want. The benefit of it is that your UIs look nice on several different screen sizes when you define them this way.
Why not just composed the layout in a table layout and set the table layout's background to a custom made graphic you make? This should work well with you. Specifically the design of your design would be like 4 columns with x rows. Then using the strechcolumn property, you should be able to accomplish what you are trying to do!
If you scale the graphic properly, then you shouldn't have this problem overall.