如何以编程方式使一个小按钮,换小文
我想使小按钮,
到目前为止,我所做的文字小,但仍然有很多的文本周围的空间。我曾尝试下面的code:
So far I have made the text small but there is still alot of space around the text. I have 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);
但我希望它出现与此相同的布局xml文件:
But i want it to appear the same as 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" />
这就像当我做到这一点编程的setMinHieght不工作。
我能怎么是做错了?
It is like the setMinHieght is not working when I do it programmatically. What could i be doing wrong?
下面是一个图像:
标记的按钮的一个在由XML创建和所有其他的编程。
The one labeled buttons was created by the xml and all the other ones programmatically.
下面是布局code整个页面:
here is the layout code for the entire 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>
编辑:
可能的解决方案:
Possible Solution:
请问有没有办法,我可以通过编程让XML布局按钮(正确显示),然后填入不同的文本,并复制它很多次,因为我需要?
Is there not a way, that i can programmatically get the xml layout button (which displays correctly), and then fill in different text and duplicate it as many times as I need?
写你的按钮名称。 txtName的话,很多的选项将上门为您服务,并选择任何你想要的。或者使用开发者的网站。
in eclipse write your button name. txtName then many options will come for you and choose whatever you want. or use developer's website.
Button txtName = new Button(getActivity(), null, android.R.attr.buttonStyleSmall);
txtName.setClickable(false);
txtName.setHeight(17);
txtName.setWidth(25);
txtName.setTextSize(10);
txtName.setMaxLines(1);
txtName.setMaxHeight(5);
txtName.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
txtName.setText(tagsList.get(i));
layout.addView(txtName);