I have a spinner with this code:
<Spinner
android:id="#+id/cover"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:prompt="#string/cover_hint"
android:layout_marginTop="10dip"
android:gravity="center"
android:layout_gravity="center_horizontal" />
Yet for some reason when it's first loaded (I am loading items in from an ArrayList<String>), it appears too small. Like the first image below. But once I select an item, then it appears normally like in the second image.
How can I get it to always appear like the second image?
You could try forcing the height with
android:layout_height="48dp"
That worked for me after I tried other things like android:padding and android:textSize, neither of which seemed to have an effect.
Related
I am currently working on an app and my layout is as follows:
I have a recyclerview holding all of my items, each item has a textview above an imageview. So the text view can expand up to 3 lines but only if needed. The recyclerview is using a gridlayout manager to display all of my items.
The problem is that currently when the text view expands to have more than 1 line it presses down the image instead of keeping it aligned with the other images in the row
What I currently have
What I want is to prevent the text view from pressing down on the image but instead build it's way up so that way the images stay normal and the text view will grow upwards like the image below.
What I want
Is there any way to achieve this? I would think it shouldn't be hard but I can't seem to find a way to accomplish this, or more likely, can't google the right terms to find the solution I'm looking for.
So I found an answer, I had to set two properties for my textview:
android:lines="3"
android:gravity="bottom"
so in the end each item had a layout below:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingStart="31dp"
android:paddingEnd="32dp">
<TextView
android:id="#+id/app_name"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_card_temp_name"
android:textSize="#dimen/product_list_text_size"
android:fontFamily="sans-serif-condensed"
android:lines="3"
android:textAlignment="center"
android:textColor="#color/app_name_product_list_color"
android:typeface="normal"
android:gravity="bottom" />
<ImageView
android:id="#+id/app_thumbnail"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="#dimen/product_list_image_dimensions"
android:layout_below="#id/app_name"
android:paddingTop="#dimen/product_list_text_bottom_padding"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Context:
I have two AutoResizeTextViews inside a LinearLayout. I would like to have the first one about 1/3 of the size of the second one, and both as large as possible. Therefore I use layout_weight=1 and layout_weight=3 as can be seen in the XML code below.
Problem:
When I hide other TextViews in the View of the Fragment (stored as mView), using:
textView7.setVisibility(View.GONE);
(..many more to GONE..)
more space gets available for the LinearLayout, and so I expect the AutoResizeTextViews to grow. However the two AutoResizeTextViews do not grow, and seem to keep their canvas size. They are moved to align to the new 1/3 ratio of the LinearLayout, so there really is space inside the LinearLayout.
When the Activity and the View is restarted upon device reorientation (I do not retain the Fragment) they DO change as expected, apparently the canvas is redrawn correctly then. How can I make the AutoResizeTextView to be redrawn correctly without have to turn the device?
Already tried:
mView.forceLayout();
mView.refreshDrawableState();
mView.requestLayout();
mView.invalidate();
linearLayoutAutoFit.invalidate();
tvTimer.invalidate();
tvTimer.setTextsize(999);
is all not working, the Text is not adjusted to the new size.
XML code:
<LinearLayout
android:id="#+id/linearLayoutAutoFit"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/viewline2"
android:layout_below="#id/progressBar3"
android:layout_alignParentLeft="true"
>
<AutoResizeTextView
android:layout_weight="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/Ready"
android:id="#+id/textViewAction"
android:textSize="999sp"
android:textColor="#ADFF2F"
android:singleLine="true" />
<AutoResizeTextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/tvTimer"
android:textColor="#fff"
android:text="#string/init_time"
android:textSize="999sp"
android:visibility="visible"
android:singleLine="true" />
</LinearLayout>
instead :
android:layout_height="wrap_content"
type :
android:layout_height="0dp"
Although the answer by Kastriot was very close, and also part of the solution, I found the solution today by testing the values inside the AutoResizableTextView class with Log outputs. The mistake I made was that I also had
android:layout_width="wrap_content"
Because of that, upon layout change, the width of the AutoResizableTextView was not adjusted! As a consequence, the text could not grow in size. Therefore the setting for the width should be:
android:layout_width="fill_parent"
such that the width of the AutoResizableTextView is large enough to fit a larger text.
Let me show you two links to demonstrate my point:
http://i.snag.gy/QP1i2.jpg (The ListView is 60 pixels)
http://i.snag.gy/DvXsL.jpg (The ListView is 61 pixels)
The whole file is done with an outer Vertical LinearLayout to provide weighted percentages (e.g. the ListView is 75%, the search part is 4%, so on and so forth) independent of device screen size. Within that outer LinearLayout I have a nested Layout (Linear or Relative) depending on my needs for the particular row.
It works beautifully, except for the last part. And it seems a lot of the items I try adding end up messing the formatting so I'm not sure if the problem is how I'm doing the ListView. Anyways, here's the relevant code:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:background="#null"
android:layout_weight="0.75"
android:paddingLeft="0dip" >
<ImageView
android:id="#+id/searchdivider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:contentDescription="#string/desc"
android:src="#drawable/searchdivider" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/searchdivider" >
</ListView>
</RelativeLayout>
Thank you for your help!
EDIT: I should add that I don't want the height to be 60dp, obviously. I want it to fill_parent; however I picked the arbitrary value of 60 and 61 to figure out exactly what change makes the layout mess up.
2nd EDIT: I think I figured out the problem. It seems when I make the Theme AppCompat, it looks and acts fine. But when I make the Theme NoTitleBar (with or without fullscreen) then it acts all screwy. I haven't changed it in the manifest but rather the place in the graphical layout that lets you modify it for that one activity only.
Any suggestions?
android:gravity="left" on imageView and android:gravity="right" on the other listView
I have some text I want to display in case of error. I can do something like this:
<TextView
android:id="#+id/error_message"
android:textColor="#color/red"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Error: something is wrong. "
/>
But this element would just take up space on the screen and make that space blank. Is there any way to not have it take up the blank space, and when it is shown so that the elements below it would move down so make space?
Thanks!
use:
android:visibility="gone"
I have in my application a listview with an adapter that uses different layouts for the items.
I want the result to be like in the attached exp_result.png.
http://imageshack.us/photo/my-images/717/expresult.png/
But unfortunatly - I get like in result.png.
http://imageshack.us/photo/my-images/839/resultf.png/
The problem is that image stretches on the screen not the way I wanted.
Any ideas?
Maybe other solution to this layout - maybe built in?
Drawables are in the links, since I cannot upload images. The original picture is like in the first listview item in the exp_result.png. I want to use 1 picture for each - top, buttom and middle and to be used no matter the listview item size. XML is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_up" >
<TextView
android:id="#+id/name_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/number_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
I can really really use some help here.
Yoav
This may be a good application of the 9-patch image type:
9-Patch