当键盘出现并隐藏工具栏(FrameLayout)时,我的屏幕大小调整到顶部,我只需将聊天项目滚动到顶部并将框架布局保持在顶部。我尝试了谷歌和SO的一些例子,但对我没有任何帮助。
<activity
android:name=".screen.workshiftscreen.WorkShiftActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait" />
Run Code Online (Sandbox Code Playgroud)
经过一些编辑后我的片段布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_second"
android:orientation="vertical">
<FrameLayout
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="@dimen/space_large_s"
android:background="?attr/bg_main"
android:padding="@dimen/space_small_m">
<TextView
*params* />
<ImageView
*params* />
</FrameLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/edit_bar"
android:layout_below="@+id/title">
<android.support.v7.widget.RecyclerView
android:id="@+id/messages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/space_medium_l"
android:paddingRight="@dimen/space_medium_l"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/edit_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<View
*params* />
<LinearLayout
*params*>
<EditText
android:id="@+id/message_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="@string/prompt_message"
android:imeActionId="@+id/send"
android:imeActionLabel="@string/action_send"
android:imeOptions="actionSend"
android:maxLines="6"
tools:ignore="Autofill,InvalidImeActionId,TextFields" />
<ImageButton …Run Code Online (Sandbox Code Playgroud) 我想在 Android Room 中使用预先填充的数据库。我找到了一种通过使用回调来实现它的方法,并填充了数据库文件。但是出了点问题,我确定数据库复制正常,但在设备监视器和android模拟器中它仍然为空。你能帮我么
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
private static final String DB_NAME = "base.db";
static Context ctx;
public abstract Dao dao();
public static AppDatabase getDatabase(Context context) {
if (INSTANCE == null) {
ctx = context;
synchronized (AppDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context,
AppDatabase.class, DB_NAME)
.allowMainThreadQueries()
.addCallback(rdc)
.build();
}
}
}
return INSTANCE;
}
private static RoomDatabase.Callback rdc = new RoomDatabase.Callback() {
public void onCreate(SupportSQLiteDatabase db) {
new PopulateDbAsync(INSTANCE, …Run Code Online (Sandbox Code Playgroud) 下午好。我在应用程序中创建了一个现有的数据库。我想通过 Room 对她讲话,但出现错误IllegalArgumentException: Cannot provide null context for the database.。我的代码如下所示:
@Database(entities = {Series.class}, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
private static final String DB_NAME = "base.db";
public abstract CymbalDao cymbalDao();
public static AppDatabase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (AppDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context,
AppDatabase.class, DB_NAME)
.allowMainThreadQueries()
.build();
}
}
}
return INSTANCE;
}
}
Run Code Online (Sandbox Code Playgroud)
数据库位置:
..\src\main\assets\base.db
Run Code Online (Sandbox Code Playgroud)
我想知道我做错了什么,也许能听到一些提示,谢谢! …
android ×2
android-room ×2
adjustpan ×1
database ×1
filestream ×1
input ×1
populate ×1
scrollview ×1