我试图使 OutlinedTextField (见下图)充当“wrap-content”。理想的情况是它足够大以适合内部文本500g并在用户编辑字段时扩展和收缩。如果我没记错的话,可以使用(非 Compose)ConstraintLayout 来处理旧视图,但在 Compose 中这不起作用。
到目前为止,我已经尝试调整各种修改器(每个修改器都是单独的):
.defaultMinSize(minWidth = 10.dp)
.width(IntrinsicSize.Min)
.widthIn(1.dp, Dp.Infinity)
.requiredWidth(IntrinsicSize.Min)
Run Code Online (Sandbox Code Playgroud)
我也尝试将 放入RowCompose 中ConstraintLayout,但似乎没有任何效果
如果我将尺寸修改器设置为较小的宽度,它确实会减小宽度,但不再扩展......
有人能够实现这一点吗?
AppCompatActivity onBackPressed()方法无法在我的活动中触发.
我看到后退箭头按钮并在按下时获取动画,但没有其他任何事情发生.还重写onKeyDown()具有相同的效果.它不被称为.
我花了很多时间研究这个没有运气.似乎没什么用.有人有类似的问题吗?也许这是一个已知的错误?
我的Activity.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.litenote.android.BackTestingActivity2Activity">
<include
android:id="@+id/appBar"
layout="@layout/app_bar" />
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:titleTextAppearance="@color/textWhite"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:popupTheme="@style/CustomPopupMenuTheme">
Run Code Online (Sandbox Code Playgroud)
活动Java文件
package com.litenote.android;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import com.superpad.android.R;
public class BackTestingActivity2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_back_testing_activity2);
Toolbar actionBar = ((Toolbar) findViewById(R.id.appBar));
setSupportActionBar(actionBar);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
@Override
public void onBackPressed() …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个可以动态更新的列表,它可能会更改几个或多个字段。的初始更新updateItems()很好,一切都按其应有的方式显示,但是 updateOneItem 的连续更新会被 Jetpack Compose 忽略。
// ****ViewModel code
val _itemList: MutableStateFlow<List<Item>> = MutableStateFlow(emptyList())
fun updateItems() {
viewModelScope.launch {
_itemList.value = itemRepository.getItems()
}
}
fun updateOneItem(newVal:Int){
_itemList.value[_itemList.value.indexOf(item)].weight = newVal
//this is where I cannot have an update show up in compose no matter what
_itemList.tryEmit(_itemList.value)
}
// ****continued ViewModel Code
Run Code Online (Sandbox Code Playgroud)
我一直在尝试复制列表,也尝试过mutableStateListOf,但到目前为止没有任何效果。
I've been trying to build a list with a Card in it formatted like this:
The difficulty here is that the title e.g. "Bread" and ingredient name e.g. "Flour" can be very long and thus I want to have an ellipsis to keep things manageable i.e. "My Long Flour name" will be displayed as "My Long Flou..." or as much space as is allowed. The picture size and the gram and percent widths are constant .dp values.
Ellipsis worked fine …
android android-jetpack-compose android-jetpack-compose-layout android-compose-layout