Android stop textview from increasing it's size - java

I have a quick question... I'm trying to make small test app for android just to see what it can do... So.. On start android sets textview.text to some text from shared prefs and increases textview size vertically.. I can't understand why.. I'm using tableview with the row of textviews in each row..
The xml code looks something like this:
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="5.1"
android:background="#F8F8FF"
android:gravity="fill_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="10sp"
android:textStyle="normal" />
</TableRow>
Is there anyway to stop that textview from resizing? Or there is some attribute I have missed..?
Thanks

on your TableRow you have
android:layout_height="wrap_content"
change to a fix height or to some relative height with "layout_weight".
If you say to android wrap to content, the rows will increase/decrease to fit his content.
Edit: i see your layout_weight, but you have 1, i think you don't know how to use it. weight repart the width and height with this weight, so think, you have 5 rows so if 1 is the total weight 1/5=>0.2 will be your weight per row.
To the weight will apply, you need to say which dimension is based on weight.
so you need to put this
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.2" >
You can read more here:
http://developer.android.com/guide/topics/ui/layout/linear.html

Related

Text of TextView after rotation is missing characters

I want to use a text view in my Android layout, the text should be rotated by 90 degrees to the left. The width of the text view is rather small (20dp). My code looks like this:
<TextView
android:id="#+id/txtVw"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:minWidth="20dp"
android:maxWidth="20dp"
android:paddingEnd="6dp"
android:rotation="270"
android:text="Test"/>
The rotation is done, but only those characters are shown that would be visible without the rotation - but there is enough space to show all of them. Does anyone have an idea?
I think it is really a bug, but I found a solution without a custom TextView by my own - I post it if someone else needs a solution for this:
<TextView
android:id="#+id/txtVwOne"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:height="20dp"
android:gravity="end"
android:maxWidth="40dp"
android:minWidth="40dp"
android:rotation="270"
android:text="Test" />
<TextView
android:id="#+id/txtVwTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_weight="1"
android:layout_marginLeft="-20dp"
android:minHeight="40dp" />
The trick is to set the min and max width to a value that will allow the text not to be cut in horizontal alignment. The layout height must be set to the height you want it to be. The height attribut must be set to target width of the text view. The following text view must contain android:layout_marginLeft="-20dp" to make sure that it is moved by 20 dp to the left (the target position).

Size of ImageViews (with VectorDrawables) in RecyclerView

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.

Can't set the background of my EditText

I have this in my fragment xml file:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.gelasoft.answeringball.MainActivity$PlaceholderFragment"
android:background="#drawable/wg_blurred_backgrounds_14"
>
<ImageView
android:id="#+id/sphereIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/magicBallDescr"
android:src="#drawable/rsz_31mystic" />
<LinearLayout
android:id="#+id/table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/sphereIcon"
android:orientation="vertical" >
<TextView
android:id="#+id/txtAnswer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/txtQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#string/textHint"
android:inputType="textMultiLine"
android:lines="6" />
<Button
android:id="#+id/btnAsk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btnAskQ"
android:paddingEnd="#dimen/activity_vertical_margin"
/>
</LinearLayout>
</RelativeLayout>
and here is how it looks:
Now I would like to set a different background image on the EditText, so I edited the xml and make it like:
<EditText
android:id="#+id/txtQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#string/textHint"
android:inputType="textMultiLine"
android:lines="6"
android:background="#drawable/background"/>
But Now the background I set on the EditText is taking the wholw LinearLayout space.
Here is how it looks in the editor after the changes:
Why is it taking the whole place and hiding the button?
What am I missing here? I'm sure it is something pretty small, but I'm not able to spot it.
I am not sure but i guest that your background image so big. you can try small width and height type image replace of that. Hopefully you can solve this problem. Best of luck!
You're suffering from an out of memory exception, as visible in the last few lines of your stacktrace.
The solution would be to reduce the size of the drawable being used as a background. It's just an EditText, and it's small size doesn't warrant a high resolution file as a background.
This can be done using a variety of image editing software, from Photoshop to Microsoft Paint.
With Paint:
Step 1: Open image in Paint.
Step 2: Click on the "Resize" button at the top, next to your toolbox.
Step 3: Reduce the size of your image to an appropriate value.
Step 4: Save the image in your drawable folders.
Step 5: If you're using Eclipse, right-click on your project and click on "Refresh"
Step 6: Launch your app again.
Now for the expansion of the EditText:
You're EditText height is set to wrap_content. When you set an image as it's background, that too becomes it's content. Hence, you're EditText bloats itself to accomodate it's new background.
A solution would be to hardcode the height like
android: layout_height="30dp" though the ability to use this depends on your requirements.

Android Java Justified tablerow in linear layout

I have a table row in a linear layout
The table row is set to fill parent
I have three objects inside the tablerow a textview then a editbox and then a buttong
they all line up horizontally
i want the textview on the left to be fixed at 100p width
I want the button on the right to be fixed at 50dp width
how do i set the editbox in the middle so that all three fill the width of the screen which might vary from device to device
I have tried various combinations of match and wrap but cant seem to get it
Any ideas
Mark
You have to use layout_weight for particular child of your view group or use relativelayout may solve your problem and please post you layout XML.
Try the following, using layout_weight:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="#+id/textView" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_weight="1" />
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/button" />
</LinearLayout>
That's when LAYOUT WEIGHTS come in handy.
For the fixed elements, just assign width & height as usual.
For the elastic ones, set "0dp" as the size you want to be elastic, and enter a weight in the weight field (layout parameters of a linearlayout).
Which weight?
If you only have one elastic element, it doesnt matter. If you have 2, then the available space will be distributed proportionally between weights. So if you wanted 2 elastic elements, one twice the size of the other, you'd assign weights 1 & 2.
By the way, heavy use of LinearLayouts with weight are somewhat discouraged because it takes Android twice the time to calculate their size. If your table has a lot of rows, you will certainly notice it's not as fast as fixed elements.

TextView on android only shows two lines worth of text in either orientation

if the text is longer than the the width the textview, after the second line, it cuts it and adds "..." to the end of it. It doesnt matter the orientation, it will just display more text until the end of the second line, here is the textview XML:
<TextView android:id="#+id/ContentViewerDescription"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="20"
android:textColor="#999999"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"/>
change to android:layout_height="wrap_content"
and delete android:ellipsize="end"

Categories