当它超过布局按钮被挤压 [英] button is squeezed when it exceeds layout
问题描述
在我的code,我创建按钮dinamically。当我创建多个按钮如下问题:
In my code, I create buttons dinamically. When I create multiple buttons is the following problem:
我如何得到它时,它发生在按钮被放下?
How do I get it when it happens the button is put down?
我的code:
private void showGlossary(String ContentTab) {
LinearLayout layout;
LinearLayout.LayoutParams p;
layout = (LinearLayout) findViewById(R.id.GlossaryTab1);
p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.FILL_PARENT
);
Glossary = (TextView) findViewById(R.id.glossary);
Glossary.setText("Glossário:");
while (ContentTab.indexOf("<gloss") != -1) {
ContentTab = ContentTab.substring(ContentTab.indexOf("<gloss"));
uri = ContentTab.substring(ContentTab.indexOf("<gloss") + 1, ContentTab.indexOf(">"));
Button myButton = new Button(this);
myButton.setText(Html.fromHtml(ContentTab.substring(ContentTab.indexOf(">") + 1, ContentTab.indexOf("</gloss>"))));
myButton.setLayoutParams(p);
myButton.setContentDescription(uri);
layout.addView(myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Toast.makeText(ShowPhytoterapicActivity.this, Html.fromHtml(getGlossaryItem(view.getContentDescription().toString())), Toast.LENGTH_LONG).show();
}
});
if(ContentTab.indexOf("</gloss>") != -1)
ContentTab = ContentTab.substring(ContentTab.indexOf("</gloss>") + 9);
}
}
我的XML:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/GlossaryTab1"
android:orientation="horizontal"
>
</LinearLayout>
谁能帮我?谢谢!
Can anyone help me? Thanks!
推荐答案
您可以所有按钮的权重设置为1,但是这将导致所有的按键成为压扁。
You could set all of your buttons' weights to 1, but that would cause all of your buttons to become "Squished".
你觉得一个 HorizontalScrollField
将工作?我认为这可能是最好的解决方案。
Do you think a HorizontalScrollField
would work? I think that may be the best solution.
只是包装你的的LinearLayout
在 HorizontalScrollField
并添加按钮在的LinearLayout
你现在的样子。
Just wrap your LinearLayout
in a HorizontalScrollField
and add your buttons to the LinearLayout
as you are now.
这篇关于当它超过布局按钮被挤压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!