活动未显示

发布于 2024-10-21 17:54:44 字数 2990 浏览 1 评论 0原文

我有一个带有各种项目的线性布局的活动,但是当我运行该应用程序时,我没有显示任何内容。

请帮忙:-)

<LinearLayout
    mlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50px"
        android:id="@+id/TitleBarLayOut"
        android:background="@drawable/titlebar_gradient">
    </LinearLayout>
    <LinearLayout android:id="@+id/topLayout" android:layout_width="fill_parent" android:layout_height="70px" android:background="#FFFFFF">
    <ImageView android:id="@+id/coverArt" android:layout_width="60px" android:layout_height="60px" android:paddingLeft="10px" android:paddingTop="10px"></ImageView>
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistTitle" android:text="TextView" android:layout_height="30px"></TextView>
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistMember" android:text="TextView" android:layout_height="30px"></TextView>
    </LinearLayout>
    <LinearLayout android:id="@+id/bottomLayout" android:layout_width="fill_parent" android:layout_height="70px" android:background="#FFFFFF">
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistDescriptions" android:text="TextView" android:layout_height="fill_parent"></TextView>
    </LinearLayout>
</LinearLayout>

setContentView(R.layout.playlistview);

Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();

LinearLayout titlebar = (LinearLayout) findViewById(R.id.TitleBarLayOut);

FeaturedButton = new Button(this);
FeaturedButton.setText("Featured");
FeaturedButton.setGravity(Gravity.LEFT);
int FeaturedButtonWidth = 50;

playButton = new Button( this );
playButton.setText("Play");
playButton.setGravity(Gravity.RIGHT);
int playButtonWidth = 50;

int titleTextWidth = ((screenWidth-playButtonWidth)-FeaturedButtonWidth);
titleText = new TextView(this);
titleText.setGravity(Gravity.CENTER);
titleText.setTextColor(Color.WHITE);
titleText.setTextSize(14);
titleText.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);

titlebar.addView(FeaturedButton, new LinearLayout.LayoutParams(
50, LayoutParams.WRAP_CONTENT));

titlebar.addView(titleText, new LinearLayout.LayoutParams(
titleTextWidth, LayoutParams.WRAP_CONTENT));

titlebar.addView(playButton, new LinearLayout.LayoutParams(
50, LayoutParams.WRAP_CONTENT));

CoverArtDisplay = (ImageView) findViewById(R.id.coverArt);
PlaylistTitleDisplay = (TextView) findViewById(R.id.playlistTitle);
PlaylistMemberDisplay = (TextView) findViewById(R.id.playlistMember);
PlaylistDescriptionsDisplay = (TextView) findViewById(R.id.playlistDescriptions);

I have an activity with a linear layout with various items but when i run the app i dont get anything displayed.

Please help :-)

<LinearLayout
    mlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50px"
        android:id="@+id/TitleBarLayOut"
        android:background="@drawable/titlebar_gradient">
    </LinearLayout>
    <LinearLayout android:id="@+id/topLayout" android:layout_width="fill_parent" android:layout_height="70px" android:background="#FFFFFF">
    <ImageView android:id="@+id/coverArt" android:layout_width="60px" android:layout_height="60px" android:paddingLeft="10px" android:paddingTop="10px"></ImageView>
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistTitle" android:text="TextView" android:layout_height="30px"></TextView>
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistMember" android:text="TextView" android:layout_height="30px"></TextView>
    </LinearLayout>
    <LinearLayout android:id="@+id/bottomLayout" android:layout_width="fill_parent" android:layout_height="70px" android:background="#FFFFFF">
    <TextView android:layout_width="fill_parent" android:id="@+id/playlistDescriptions" android:text="TextView" android:layout_height="fill_parent"></TextView>
    </LinearLayout>
</LinearLayout>

setContentView(R.layout.playlistview);

Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();

LinearLayout titlebar = (LinearLayout) findViewById(R.id.TitleBarLayOut);

FeaturedButton = new Button(this);
FeaturedButton.setText("Featured");
FeaturedButton.setGravity(Gravity.LEFT);
int FeaturedButtonWidth = 50;

playButton = new Button( this );
playButton.setText("Play");
playButton.setGravity(Gravity.RIGHT);
int playButtonWidth = 50;

int titleTextWidth = ((screenWidth-playButtonWidth)-FeaturedButtonWidth);
titleText = new TextView(this);
titleText.setGravity(Gravity.CENTER);
titleText.setTextColor(Color.WHITE);
titleText.setTextSize(14);
titleText.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);

titlebar.addView(FeaturedButton, new LinearLayout.LayoutParams(
50, LayoutParams.WRAP_CONTENT));

titlebar.addView(titleText, new LinearLayout.LayoutParams(
titleTextWidth, LayoutParams.WRAP_CONTENT));

titlebar.addView(playButton, new LinearLayout.LayoutParams(
50, LayoutParams.WRAP_CONTENT));

CoverArtDisplay = (ImageView) findViewById(R.id.coverArt);
PlaylistTitleDisplay = (TextView) findViewById(R.id.playlistTitle);
PlaylistMemberDisplay = (TextView) findViewById(R.id.playlistMember);
PlaylistDescriptionsDisplay = (TextView) findViewById(R.id.playlistDescriptions);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花伊自在美 2024-10-28 17:54:44

我已经运行了你的项目,我认为你缺少:

android:orientation="vertical"

在你的主 LinearLayout 中。如果添加它,则会显示带有文本视图的底部线性布局。

无论如何设计都不好。将按钮移至 XML,并请重新考虑您的布局;)
希望有帮助。

I've run your project and I think you are missing:

android:orientation="vertical"

in your main LinearLayout. If you add it, the bottom linear layout with the textviews is displayed.

Anyway the design is not good. Move the buttons to XML and please rethink your layout ;)
Hope it helps.

甜宝宝 2024-10-28 17:54:44

信息如此之少,很难判断问题出在哪里。您是否使用带有 Android 插件的 Eclipse?

“我没有显示任何内容”是什么意思?应用程序是否运行,但您只看到空白视图?

您的活动是否在 AndroidManifest.xml 中列出?

Hard to tell what the problem is with so little information. Are you using Eclipse with the Android plugin?

What do you mean by "i dont get anything displayed"? Does the app run, but you just get a blank view?

Is your activity listed in AndroidManifest.xml?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文