【发布时间】:2016-02-03 12:03:15
【问题描述】:
在我的 onCreate 方法中,我一开始就设置了内容视图()
inflater = getLayoutInflater();
Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());
root = inflater.inflate(R.layout.activity_main, null, false);
// root.setBackgroundColor(color50);
setContentView(root);
... 在 onCreate() 快结束时,我调用了一个自定义 asynctask 并从中获取结果。但是,我的应用程序的屏幕一直保持黑色,直到任务完成执行。
try {
task = (DatabaseTask) new DatabaseTask().execute(new DatabaseTaskParams(activity, images));
helper = task.get();
} catch (Exception e) {
Log.e("DatabaseTask", "stack trace", e);
}
suggestions = helper.getKeywords();
为什么会发生这种情况?是因为我的 XML,还是因为 onCreate 仅在调用它之后才呈现 UI,还是其他原因?
这是我的活动根 XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_photos_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"
tools:context="dtancompany.gallerytest.MainActivity">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_add_panel"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="0dp"
sothree:umanoParalaxOffset="100dp"
sothree:umanoDragView="@+id/dragView"
sothree:umanoOverlay="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView android:id="@+id/grid_view"
android:layout_width="match_parent" android:layout_height="match_parent"
android:numColumns="auto_fit"
android:gravity="center"
android:stretchMode="columnWidth"/>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
<RelativeLayout
android:id="@+id/add_keyword_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical"
android:clipToPadding="false"
android:padding="16dp">
<EditText
android:id="@+id/edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="64"
android:hint="@string/edit_text_hint"
android:background="@android:color/transparent"
android:textSize="25sp"
android:layout_centerHorizontal="true"/>
<ImageButton
android:id="@+id/add"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/plus"
android:background="@android:color/transparent"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"
android:layout_below="@id/edit_text"/>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
<FrameLayout
android:id="@+id/listFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
【问题讨论】:
-
你使用的是 Fragment 还是 Activity ?
标签: android android-layout android-activity android-asynctask