我的button无法显示,无报错,也对比过成功的例子,实在找不到原因

ccsosnfs 2011-01-27 12:30:35
运行无任何报错,也对比了成功的例子。
真奇怪


activity1.java
package cc.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

public class activity1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//选择主视图使用的布局

TextView textview1 = (TextView) this.findViewById(R.id.textview1);
textview1.setText("textview1");

Button button1 = (Button) this.findViewById(R.id.button1);
//根据ID调用
button1.setText("button1");
button1.setBackgroundColor(Color.GREEN);


}

}


mail.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/stringAct1"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

/>

</LinearLayout>


AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.activity"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="3"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".activity1"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>


</manifest>
...全文
233 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccsosnfs 2011-01-27
  • 打赏
  • 举报
回复
谢谢啊,我还以为是visable之类的问题,设置了半天。
唉,不细心呐还是!
DrSmart 2011-01-27
  • 打赏
  • 举报
回复
android:layout_width="fill_parent"
android:layout_height="fill_parent"

你的上面的TextView的布局说明,你的文本显示框都占满屏幕了,当然你在Button中加个比重可以不要修改上面的代码,加个weight 属性在Button中
筱周 2011-01-27
  • 打赏
  • 举报
回复
main.xml中
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/stringAct1"
/>
android:layout_height="fill_parent" 这句话使得TextView的高度充满了父容器 导致下面的
按钮看不到 改成ndroid:layout_height="wrap_content" 就行了

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧