开发者

Activity not showing

开发者 https://www.devze.com 2023-02-17 00:58 出处:网络
I have an activity with a linear layout with various items but when i run the app i dont get anything displayed.

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);
PlaylistDescript开发者_如何学CionsDisplay = (TextView) findViewById(R.id.playlistDescriptions);


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消