我有一个带有各种项目的线性布局的活动,但是当我运行应用程序时,我没有显示任何内容。
请帮助: - )
<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);
答案 0 :(得分:2)
我已经运行了你的项目,我认为你错过了:
android:orientation="vertical"
在您的主要LinearLayout中。如果添加它,则会显示带有textviews的底部线性布局。
无论如何设计并不好。将按钮移动到XML,请重新考虑您的布局;) 希望它有所帮助。
答案 1 :(得分:1)
很难说出这么少的信息是什么问题。您是否将Eclipse与Android插件一起使用?
“我什么都不显示”是什么意思?该应用程序是否运行,但您只是得到一个空白视图?
您的活动是否列在AndroidManifest.xml中?