English 中文(简体)
按钮在超过布局时被挤压
原标题:button is squeezed when it exceeds layout

在我的代码中, 我创建了双名按钮。 当我创建多个按钮时, 问题如下 :

""https://i.sstatic.net/0wTti.jpg" alt="此处输入图像描述"/ >

扣子扣下来的时候我怎么弄得到?

我的代码:

    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>

有人能帮我吗?

最佳回答

您可以将所有按键重量设置为 1, 但这将使所有按键都“ 被压碎 ” 。

您认为 < code> HorizontalScroll Field 有效吗? 我认为这可能是最好的解决办法。

只需在 LinearLayout 中以 HorizontalScroll Feel 包装您的 LinearLayout , 并按现在的顺序将您的按钮添加到 LinearLayout

问题回答

将三个按钮排成一行似乎有点乱。 您可以尝试不同的布局样式, 或者三角形设置, 或者将您的 UI 设计改变为更紧凑的东西, 并改变按钮外观的流程 。

感谢大家的回答,我做了一个相同的 < code> LinearLayout 垂直 。 ) :





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签