Активность не отображается - PullRequest
0 голосов
/ 13 марта 2011

У меня есть действие с линейным макетом с различными элементами, но когда я запускаю приложение, я ничего не отображаю.

Пожалуйста, помогите: -)

<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);

Ответы [ 2 ]

2 голосов
/ 13 марта 2011

Я запустил ваш проект и думаю, что вам не хватает:

android:orientation="vertical"

в вашем основном LinearLayout.Если вы добавите его, отобразится нижний линейный макет с текстовыми представлениями.

В любом случае, дизайн не очень хорош.Переместите кнопки в XML и, пожалуйста, переосмыслите свой макет;) Надеюсь, это поможет.

1 голос
/ 13 марта 2011

Трудно сказать, в чем проблема с таким небольшим количеством информации. Используете ли вы Eclipse с плагином для Android?

Что вы подразумеваете под "я ничего не показываю"? Приложение запускается, но вы просто видите пустое представление?

Ваша активность указана в AndroidManifest.xml?

...