I am having a table with each row containing 3 buttons.
Now, I want to add some padding between each buttons in a single row.. How can I do that..?
When i add this statement in my code,
tableRow.setPadding(20,20,20,20);
I am able to observe padding but between each row.
I want to have padding between each button...
Note: I want to do it from java programmatically, not from xml..
You can do it in this way:
<Button android:id="#+id/myBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Click Me"
/>
padding is the margin inside the button between the edges and the text.
This will increase button size not the distance between buttons
You need to use margin like this in your XML inside your button tag
android:layout_margin="10dp"
this will set all margins to 10dp
if you need to set margins only for certain side use :
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
I hope this helps you out.
Regards
you need to add padding to your buttons.
btn1.setPadding(left, top, right, bottom);
btn2.setPadding(left, top, right, bottom);
.
.
.
also make sure to take units in dp, hard-coded values will result in uneven padding on devices with various resolutions.
The TableRow class, as with all View subclasses, indeed has a setPadding method.
However, since you mention that you found setMargin, I believe you are looking at the TableRow.LayoutParams instead of the TableRow itself.
Margins are set in a View's LayoutParams, whereas padding is set on the View.
You need to use margin for your buttons instead of padding for the whole row. Because padding is actually a space between the button text and border, e.g. inner spacing, while margin is the space between button border and the it's container (row) e.g. outer space
Depending on what look you are trying to achieve, use something like this
<Button android:id="#+id/yourButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="Button1"
/>
<Button android:id="#+id/yourButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="Button2"
/>
<Button android:id="#+id/yourButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="Button3"
/>
Related
I am having trouble formatting the text inside my button. I have tried reducing the margins and padding and using gravity, but I still seem to have a some kind of margin around the text inside the button.
I have currently positioned the text in top, but as you see it stays very low and even goes out of the button.
Here is the code I use:
<Button
android:id="#+id/counterValue"
android:layout_width="283dp"
android:layout_height="144dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:onClick="countIN"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:gravity="top|center"
android:text="0"
android:textSize="140dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
As you see, the big 0 is at the very bottom of the box. I would like it to be right in the middle and with very small margins.
Any ideas of what am I missing in my code?
I suggest you change the text size from "dp" to "sp" as in 140dp. If you want to keep this size tho, you might want to change the size for your button
The line in problem is:
android:textSize="140dp"
You only have to change the Button's height to wrap_content:
android:layout_height="wrap_content"
You can't have fixed height for the Button and fixed textSize and expect the text to be centered correctly.
Edit
Set this attribute:
android:includeFontPadding = "false"
I have one textview which size is 50 dp. I got this result like the picture below.
I want to remove bottom spaces in my textView ,because its height depend on the text size. And I want to receive background only into my quotation mark.
Is there any way to remove the unused spaces in my textView?
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="top"
android:text="“"
android:fontFamily="#font/arialbd"
android:background="#ff0"
android:textColor="#E8E9EF"
android:includeFontPadding="false"
android:textSize="50dp" />
Try this:
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="top|center"
android:text="“"
android:fontFamily="#font/arialbd"
android:background="#ff0"
android:textColor="#E8E9EF"
android:includeFontPadding="false"
android:textSize="50dp"
android:gravity="top" />
This solution works on my case. To remove bottom padding. Set the layout_height the same size as your textSize or 1dp or 2dp less.
Set includeFontPadding="false". Set android:lineSpacingExtra="0dp"
In your case you have to implement custom textView. check this example for reference.
U can try setting your bottom margin to a negative value.
Something like this:
android:layout_marginBottom="-10dp"
Let me know if its works, that is the simplest way but can be anothers...
Android: I want to have gap of 20 dp between two textview i am using relative view and have already used textview 2 should be below textview 1 , but i dont understand how to give more gap in between these 2 textviews
You can use padding or margin. I recommend margin.
<TextView
android:text="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/your_id"
android:layout_margin="20dp" />
EDIT:
Thanks to #Gabe Sechan to amplify the answer. If you want margin only in one side, you can use the specific margin instruction of the side you want. Example:
Margin only on bottom
<TextView
android:text="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/your_id"
android:layout_marginBottom="20dp" />
And the other sides
android:layout_marginTop, android:layout_marginLeft and android:layout_marginRight.
I have a activity layout which represents a form. The form contains a few form fields including an Spinner.
The layout is of type ConstraintLayout.
Because the Spinner control doesn't have a baseline i can't vertical align my "Kind" label correctly. I used 24 dp at the top as a temp. solution, but because the Spinner will increase in height i don't like this solution.
Is there a better solution to get the Kind label aligned correctly?
<TextView android:id="#+id/video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lorem Ipsum"
app:layout_constraintBottom_toBottomOf="#+id/spinner"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/spinner" />
When you anchor the bottom and top of a view to another, it will be centered relatively. This is valid vertically and horizontally.
Hope this helps.
In my experience, the TextView and the Spinner aligned better when using baseline alignment (layout_constraintBaseline_toBaselineOf).
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Repeat"/>
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="#id/textview"
app:layout_constraintBaseline_toBaselineOf="#id/textview"
android:layout_marginLeft="50dp"/>
I have the following linear layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/SearchBox">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Search: "
android:id="#+id/SearchText"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_le="#+id/SearchBox"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:id="#+id/SearchButton"/>
</LinearLayout>
As you can see, the EditText is between the view and the button. Is there any property I can set that makes the edit text fill the space between the other two controls? (Which have a fixed size, based on their static content).
Setting the Edit Text's layout width to "Fill_parent" pushes off the button (since there's no more room in the parent).
Ideally, I guess the thing to do would be to add the edit text last, specify that it should be between the other two controls, and then set it to fill width.
But I'm not sure how to do that. Any help?
use property android:weight='1' on the EditText once you have fixed the widths of the other views