It looks like this.
I want to change the text size of a checkbox in a fragment.
The text size itself became bigger, but the little field of the checkbox is now a little bit higher than the text.
I hope someone can help me with this.
Thanks
This is my code for the CheckBox:
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Text"
android:paddingTop="#dimen/my_padding"
android:id="#+id/text" />
<CheckBox
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Text"
android:textColor="#000000"
android:textSize="20dp" />
Simply set the textAppearance attribute to your desired value:
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.MaterialComponents.Subtitle1" />
Try to scale it as you need
P.S check at run time
If you got a problem with text size when you scaling
use
this
checkBox.TextSize = (int)(TEXT_SIZE/SCALE_FACTOR);
<CheckBox
...
android:scaleX="0.60"
android:scaleY="0.60"
/>
Related
for some reason, my edittext does not show the keyboard when tapped on, i have no idea what is wrong, any help would be greatly appreciated
i have tested this using an emulator and an actual device, but neither work
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification text:"
android:id="#+id/intro"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/intro"
android:id="#+id/txt_tekstNotif"
android:textSize="20dp"
android:lines="4"
android:focusable="true"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txt_tekstNotif"
android:text="#string/cre_notif"
android:id="#+id/btn_cre_notif"/>
</LinearLayout>
You need to give a size to you EditText otherwise it's size is 0.
You set it as "wrap_content" and you have no content. So you either set a background drawable to it or put some text or "hint" in it so it will have an actual size.
Just try and put android:layout_width="50dp"
android:layout_height="100"
and see if it works.
In my app I set one TextView and I noticed that there were some spaces above and below the text, as in the image below.
But my expected result is this :-
I Googled lots and found this answer link, but nothing happens.
Updated :
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50dp"
android:background="#484848"
android:textColor="#fff"
android:text="A"
android:layout_centerInParent="true"/>
This is the tag I used for displaying text.
Updated :
<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:id="#+id/rl"
tools:context=".MainActivity" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50dp"
android:background="#484848"
android:textColor="#fff"
android:text="A"
android:paddingTop="0dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
Updated Image :
Actually, its a padding of 9-patch backgrounds drawable which is by default for Android TextView background. And you are just set color to it #484848. So you don't have any solution for it.
As per my concern use the same size of height (android:layout_height) for your TextView as same as your TextSize (android:textSize="50dip") of your TextView. (instead of android:layout_height="wrap_content")
Try with below code:
<TextView android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_marginTop="-5dip"
android:textSize="50dip"
android:background="#484848"
android:textColor="#fff"
android:text="A"
android:includeFontPadding="false"
android:layout_centerInParent="true"/>
I also added some margin in negative. android:layout_marginTop="-5dip"
Hope this will help you a little bit.
android:layout_height="wrap_content" only works at certain times, for example, when you setHeight(), setWidth(), setText(), setMinHeight(), .... These methods will request the layout to wrap the content again.
But setTextSize() doesn't request the layout.
To trigger wrap_content to work again, you can call setMinHeight(0).
I am using a custom Toast and sometimes the text view gets clipped off if the field is too long:
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/toast" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/someotherview"
android:layout_alignBottom="#+id/someotherview"
android:layout_alignLeft="#+id/someotherview"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
I have tried virtually everything starting from android:gravity="fill" to android:ellipsize="marquee". Nothing seems to work. Does anyone know why?
Perhaps something like this would help you: http://www.androidviews.net/2012/12/autoscale-textview/
It re-sizes the textview (and the text) to fit in your other view.
I have a rather simple ListView row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>
When the text of "#+id/tournament_name"is long - it overlaps with the one from "#+id/tournament_winner" and I don't understand why.
I tried using android:singleLine="false"to no avail. I also tried using android:inputType="textMultiLine"as the docu says android:singleLine="false" is deprecated but then I get the warning: Attribute android:inputType should not be used with <TextView>: Change element type to
<EditText> ? so no good here as well.
I also tried using android:ellipsize="end" but this doesn't work. I assume it is because the text in the left TextView ("#+id/tournament_name") is NOT long enough to fill up the full width of the ListView (which code is not sowing here).
I was sure that if I use android:layout_width="wrap_content"the two TextView fields shouldn't overlap.
Here is an example (see the second line):
Any further ideas how this could be fixed?
android:layout_toLeftOf="#id/tournament_winner" in First TextView.
Also set android:maxLines="1" and Fix width for tournament winner because when it gets long tournament name cant see...
row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/tournament_winner"
android:maxLines="1"
android:text="NAMEEEEEEEEEEEEEEEEEEEEEEEEEEE"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="WINER"
android:textSize="25dp" />
</RelativeLayout>
Thank you very much for your answer - sorry it took me some time to respond. I ended up using your android:layout_toLeftOf="#+id/tournament_winner" but left the single line and the margin to the left unused, as the result seemed perfect to me (hope this is also the case for other devices).
One thing though - in the first text view (tournament_name) I had to use android:layout_toLeftOf="#+id/tournament_winner"and not android:layout_toLeftOf="#id/tournament_winner" - pay attention to the added +. For some reason I get an error using android:layout_toLeftOf="#id/tournament_winner": Error: No resource found that matches the given name... so it seems that it is possible and NEEDED to define the resource in the time of calling it because the system doesn't know it before it was defined.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tournament_winner"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>
You can use single text view in place of two and simply display both strings in one text view !!
This my current layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F5F5DC"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/flag_dk"
android:textColor="#000000"
android:layout_gravity="center_horizontal"
android:drawablePadding="10dip"
android:text="Danish" />
<RadioButton android:id="#+id/radio_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/flag_en"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dip"
android:drawablePadding="10dip"
android:textColor="#000000"
android:text="English" />
</RadioGroup>
</LinearLayout>
</ScrollView>
I get this:
I would like to have some space (margin) between radiobutton an the flag (it's drawable). Is it even possible?
You can do like the following:
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="match_parent"
android:layout_height="#dimen/view_size"
android:button="#null"
android:drawablePadding="100dp"
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
android:text="label" />
In my case, where I have a custom drawable shape, adding android:paddingDrwable attribure did not work but adding android:paddingLeft="5dp" did.
Where you are setting the image and the text give blank spaces before it.
for example: radiobutton.setText(" "+Text);.You will see the desired output.
I don't think it is possible to add space between the image and the radio button using the android apis. However, the answer to your question I think is to add some space in the image itself.
Use Relative Layout instead of Linear Layout it gives android:layout_margingleft & android:layout_margingRight to drop your radio buton & Images as well.
Also give android:padding="10dip"
Try it it will definitely work!!!!