I have a custom listview with ImageView and EditText , my problem is, with different image the size of imageview is different, like in photo.
How can I make sure that all images have the same size?
Image of listView
This is my XML code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="150px"
android:layout_height="150px"
android:adjustViewBounds="true"
android:layout_weight="0.1"
android:scaleType="fitXY"
android:layout_marginBottom="1dp"/>
To deal with different aspect ratio images your best approach is to choose a aspect ratio in your layout and center crop your images so they fill the available space.
<ImageView
android:layout_width="160dp"
android:layout_height="90dp"
android:scaleType="centerCrop" />
Well for better size, create linear layouts for each row containing an Imageview and Edittext.
You have set ScaleType to fitXY and that is good. Now use dp or fill_parent for Imageview size.
(Posted on behalf of the OP).
I have solved this - I have simply remove this android:layout_weight="0.1".
Related
There is a dialog with a lot of vector images. How to calculate the size of each picture for any screen?
If i use
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ava_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ava_item_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"/>
</FrameLayout>
i get this result
But i need automatically set size for imageviews. How?
In order to get all VectorDrawables of the same maximum size in Vertical Scrolling RecyclerView, you need to install in xml at the root element
android:layout_width="match_parent"
android:layout_height="wrap_content"
I suppose for horizontal scrolling the values of the parameters should be reversed.
I have a GridView which displays the user's photos. What I want to find is the exact columnWidth I have to specify so that the number of columns will vary from device to device, but always take up the entire screen (like QuickPic does). Right now my code is as follows:
//GridView inside Fragment layout file
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:horizontalSpacing="2.75dp"
android:verticalSpacing="2.75dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" />
//GridView row
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="#+id/ivPhoto"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitCenter" />
</RelativeLayout>
With my code, I get a lot of whitespace I don't want. I want it to have whitespace, but very little. I want the Grid to fill the entire screen with columns (photos), but leaving some little whitespace between them.
What would the perfect columnWidth be?
Thank you.
Making the Gridview adapt to different screen sizes is a little tricky using xml. A good solution is to adjust the size of the gridviews in your adapter's getView() method.
check out this example.
Adjust GridView to all Screen Sizes
spinner gravity only seems to work in the horizontal dimension. I would like the displayed text to on the top vertically and centered horizontally. Is this possible?
I use an xml spinner normal style like this:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:paddingBottom="5dip"
android:id="#+id/spinnerTarget"
android:gravity="top|center_horizontal"
android:textColor="#ffffff"
/>
you have wrap_content for height, so the view shrinks around the text and there is no space for the text to be positioned on the top of the view. android:gravity works only if there is enough space for the content within the activity. center_horizontal works because you have set fill_parent for the width and I assume the view takes all of the screens width, thus allowing the contents to be centered.
Try rearranging your layout so that there is more space for the view in terms of height.
cheers!
Here is what I ended up, hope i helps
<Spinner
android:id="#+id/m1_ss_spinner"
android:background="#drawable/btn_default_normal_invisible"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_gravity="top"
android:layout_below="#id/m1_ss_head"
/>
I´m trying to center, stretch, shrink the rows of a gridview but has been impossible. I´m inflating a gridview with 7 imageviews. The gridview shows the imageviews like this:
[imageview][imageview][imageview][imageview]
[imageview][imageview][imageview]
I need that the gridview looks like this:
[imageview][imageview][imageview][imageview]
[imageview][imageview][imageview]
this is my gridview code:
<GridView android:id="#+id/player_tell_grid"
android:layout_marginTop="10dp" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="#id/player_tell_message"
android:verticalSpacing="10dp" android:horizontalSpacing="10dp"
android:numColumns="4" android:columnWidth="45dp"
android:layout_marginLeft="15dp" android:layout_marginRight="10dp"
android:stretchMode="columnWidth" android:gravity="center"
android:background="#drawable/bg_tell" android:shrinkColumns="*">
</GridView>
Thanks for your help.
What are you trying to do is not possible with a single GridView.
Either add a second one (with different padding) or consider a different layout if you have a limited number of items: TableLayout, RelativeLayout maybe?
Just a quick question about how you would go about implementing this. I want there to be buttons at the bottom of the screen, but if the screen size is larger, more buttons would be added.
For example, at a small screen size, there might be 4-5 buttons at the bottom, but if you ran it on a tablet or something similar, there would be maybe 20 buttons.
Any suggestions? It can't scroll either, it just has to dynamically fill the layout with buttons.
Thanks.
To put buttons at the bottom of a layout, do something like this to your layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout">
<LinearLayout
android:layout_height="wrap_content"
android:id="#+id/button_layout"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:gravity="center">
<Button
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"></Button>
<Button
android:id="#+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"></Button>
<Button
android:id="#+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"></Button>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_layout"
android:id="#+id/content">
<ListView
android:id="#+id/ListView01"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ListView>
</FrameLayout>
</RelativeLayout>
To change how many buttons are shown based on the screen size, you should implement separate layouts for Multiple Screen Sizes..
http://developer.android.com/guide/practices/screens_support.html
Sounds like you want to create your own custom layout class. That or just fill a LinearLayout (for instance) until you run out of screen space.
If you know the size of your buttons in pixels you could use DisplayMetrics to get the dimensions of the screen then calculate how many buttons will fit in your allotted space.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.heightPixels givs absolute height in pixels
metrics.ydpi gives exact physical pixels per inch of the screen
and metrics.density gives logical density for scaling purposes
see here: http://developer.android.com/reference/android/util/DisplayMetrics.html
then just do something like
do{
Button button=new Button(context);
button.setText("yada yada")
button.allYoursettings....
.
.
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LinearLayout layout=(LinearLayout) findViewById(R.id.yourlayout);
layout.addView(button,p);
} while(havespaceleft);