嗨,我想知道是否有使用Android数据绑定库的此函数的xml标记或如何在没有findViewById()方法的情况下实现此功能
谢谢
我创建了这个绑定适配器
@BindingAdapter("adapter")
public static void setAdapter(RecyclerView view, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
view.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
并以XML格式设置
app:adapter="@{com.package.Adapter}"
Run Code Online (Sandbox Code Playgroud)
它会带来各种错误.我想要的是做与使用XML中的LayoutManager相同的事情
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
Run Code Online (Sandbox Code Playgroud)
你知道如何通过课程来解决这个问题吗?
PS我不想在XML中传递变量引用,因为假设我只想使用XML.
我正在使用FileProvider在Android Nougat上拍照,这是我的代码
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mypackage.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
Run Code Online (Sandbox Code Playgroud)
file_paths.xml:
<paths>
<files-path name="img" path="images/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
Java的:
String fileName = "cameraOutput" + System.currentTimeMillis() + ".jpg";
File imagePath = new File(getContext().getFilesDir(), "images");
File file = new File(imagePath, fileName);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final Uri outputUri = FileProvider.getUriForFile(activity, "com.mypackage.fileprovider", file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
getContext().grantUriPermission(
"com.google.android.GoogleCamera",
outputUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION
);
cameraIntent.setFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
activity.startActivityForResult(cameraIntent, ACTIVITY_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
相机活动开始,成功拍照,但活动结果不正常,我在错误日志中看到的唯一的事情是
CAM_StateSavePic:将结果保存到URI时发生异常:Optional.of(content://com.mypackage.fileprovider/img/cameraOutput1469383289530.jpg)FileNotFoundException:是一个目录
编辑 错过了File#createNewFile();
如何在Flutter中获取小部件在屏幕上的绝对坐标?
或其在父级中的偏移量
例:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Simple app',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SimpleScreen(
title: 'Simple screen',
),
);
}
}
class SimpleScreen extends StatefulWidget {
final String title;
SimpleScreen({Key key, this.title}) : super(key: key);
@override
_SimpleScreenState createState() => new _SimpleScreenState();
}
class _SimpleScreenState extends State<SimpleScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container( …Run Code Online (Sandbox Code Playgroud) 如何从 ListView 中删除过度滚动效果(Android 上的圆形覆盖,iOS 上的反弹)
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Title',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: ListView.builder(
shrinkWrap: true,
itemCount: 3,
itemBuilder: (BuildContext context, int index) {
return Text('Some text');
}),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢。这里有更多的文字来补偿代码/文本比例
嗨,我有一个 RecyclerView,用于在两列中显示图像。电影的 ArrayList 包含 60 个用于图像的 URL 字符串。因此图像可以很好地加载到 ImageViews 中。当我向下滚动时,一切正常,然后我到达底部并向上滚动,有一段时间它滚动正常,但随后滚动到最顶部,我实际上看到了尝试加载之间的所有照片。我寻找了这个问题,但没有找到这个滚动问题的原因。但是如果我在列表中只有 20 个项目,一切都很好
这是适配器的代码:
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private ArrayList<Movie> movies;
private Context context;
private int newWidth;
private int newHeight;
public CustomAdapter(ArrayList<Movie> movies, Context context) {
this.movies = movies;
this.context = context;
int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
int orientation = context.getResources().getConfiguration().orientation;
newWidth = screenWidth / (orientation == Configuration.ORIENTATION_LANDSCAPE ? 3 : 2);
newHeight = (int) (((double) newWidth / 185) * 278);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { …Run Code Online (Sandbox Code Playgroud)