当它超过布局按钮被挤压 [英] button is squeezed when it exceeds layout

查看:239
本文介绍了当它超过布局按钮被挤压的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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".

你觉得一个 Horizo​​ntalScrollField 将工作?我认为这可能是最好的解决方案。

Do you think a HorizontalScrollField would work? I think that may be the best solution.

只是包装你的的LinearLayout Horizo​​ntalScrollField 并添加按钮在的LinearLayout 你现在的样子。

Just wrap your LinearLayout in a HorizontalScrollField and add your buttons to the LinearLayout as you are now.

这篇关于当它超过布局按钮被挤压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆