当前位置: 首页 > 面试题库 >

活动布局未显示

和飞翔
2023-03-14
问题内容

我试图使用此代码从我的主要活动中调用第二个活动

Intent goToOrder = new Intent(ListOfOrdersActivity.this, OrderSummaryActivity.class);
startActivity(goToOrder);

作为我的OrderSummaryActivity:

public class OrderSummaryActivity extends ActionBarActivity {

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.order_summary);
    }
}

但是布局不会在此活动中显示,只是空白页。这是布局的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/name"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"
        />
    <TextView
        android:id="@+id/order_resume_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/quantity"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_quantity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/whipped_cream"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_whipped_cream"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/chocolate"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_chocolate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/order_summary_total"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_total"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>

有什么提示吗?


问题答案:

尝试将 OrderSummaryActivity.class 更改为:

    public class OrderSummaryActivity extends ActionBarActivity
    {

        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.order_summary);
        }
    }


 类似资料:
  • 我已经在这里看了这个问题,但是我仍然找不到我做错了什么。Logcat中没有错误,并且肯定有数据被传递给它进行制作。这是我的设置: 这一切都发生在我在Android Studio中手动放置的元素下面。我有一个滚动视图。在这个滚动视图中,我有一个LinearLayout,即parentLayout,它被传递给这个类。此方法应添加另一个水平线性布局,

  • 在Android中,我需要将第二个页面滑动到另一个页面上。 布局1覆盖页面左侧的80%。布局2显示其余的20%。往右走。 然后我需要拖动/滑动布局2在布局1的顶部,并将其滑回。

  • 问题内容: 我正在为我的学生编写MathQuiz,包括用于渲染的JLatexMath和用于蜂鸣器的jinput。问题是,有时(像每四次一样)当我启动程序时,所有组件都不可见。它们在调整JFrame大小后出现。首先,我想到了jinput或jlatexMath库中的Bug,但是即使使用最小的代码,我也会遇到相同的错误: 代码有什么问题? 问题答案: 首先移到构造函数的末尾。 而不是去这里… 移到这里…

  • ![我已经以线性布局(下面给出的代码)对其进行了编码,但想知道如何使用相对布局进行相同的操作,或者这只是一个考虑到布局的坏主意? 线性布局 - ][1] 使用相对布局时,我的ImageView不会显示在屏幕上:

  • 我有一组AL约束来定位一个子vc,它有两个位置,展开和折叠。 我发现,当我添加折叠约束时,带有常量的上锚到下锚约束,当第一次创建vc时,当我激活它时,似乎有额外的间距。似乎是因为当时没有实际的高度。 当我在viewDidLayoutSubviews中添加约束时,额外的间距消失了,约束行为正常。除了现在在动画中的约束之间切换时,切换到展开约束和约束打断时,无法停用折叠的约束。可能是因为在整个过渡动画

  • 问题内容: 我不能再开始新项目了。我就是这样 启动Eclipse。 新的Android应用程序 最低 API 8 目标 API 18 编译 API 19 创建活动:选中 活动名称: 布局名称: 完 当我打开项目时(它甚至没有打开应有的状态):- src 文件夹为空 -res / layout 文件夹为空 但是 AndroidManifest.xml 存在。之前它运行得非常好,我能够创建项目,然后突