I want to make small buttons,
So far I have made the text small, but there is still a lot of space around the text. I tried the code below:
LinearLayout layout = (LinearLayout) view.findViewById(R.id.fragment_dds_tag_linearLayout); Button txtName = new Button(getActivity(), null, android.R.attr.buttonStyleSmall); txtName.setClickable(false); txtName.setTextSize(5); txtName.setMaxLines(1); txtName.setMaxHeight(40); txtName.setMinHeight(0); txtName.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); txtName.setText(tagsList.get(i)); layout.addView(txtName);
But I want it to look just like this layout XML file:
<Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="5dp" android:textSize="10sp" android:text="Button" />
It looks like setMinHieght doesn't work when I do this programmatically. What can i do wrong?
Here is the image:
One labeled buttons were created using xml and all other programmatically.
here is the layout code for the whole page:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/fragment_dds_rating_ratingBar_textView_heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Tags" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="5dp" android:textSize="10sp" android:text="Button" /> <LinearLayout android:id="@+id/fragment_dds_tag_linearLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" > </LinearLayout>
EDIT: Possible Solution:
Is there no way that I can programmatically get the xml layout button (which displays correctly) and then fill in another text and duplicate it as many times as I need?
source share