似乎在a ViewStub中膨胀时ConstraintLayout,结果视图已经失去了所有约束.我想我们可以使用膨胀视图来定义约束ConstraintSet,但这种方法会失败ViewStub.
有没有办法做到这一点?
我读过有关tools:context 的内容,发现它在开发时非常有用,因为它可以帮助我了解我使用了当前 Xml 的哪些活动。
我的问题是:
我有 2 个活动,使用相同的 Xml 文件(重复使用相同的layout.xml文件),但我无法使用tools:context
如何
tools:context在 Xml 中使用链接 2 个活动?
我努力了:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
tools:context="com.example.mytestapp.MainActivity,com.example.mytestapp.Main2Activity">
<!-- Other Layouts Here -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这给了我红线
还尝试使用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools2="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.mytestapp.MainActivity"
tools2:context="com.example.mytestapp.Main2Activity">
<!-- Other Layouts Here -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这不会给出红线,但是当我运行它们时,我收到以下错误:
Error:(2) error: duplicate attribute.
Error:(2) duplicate attribute.
Run Code Online (Sandbox Code Playgroud) class CholesterolPagingFragment: Fragment() {
companion object {
fun newInstance(): CholesterolPagingFragment {
val args = Bundle()
val fragment = CholesterolPagingFragment()
fragment.arguments = args
return fragment
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_paging_cholesterol, container, false)
return view
}
}
Run Code Online (Sandbox Code Playgroud)
我在Kotlin中编写了上面的代码来初始化一个片段.虽然我无法找到将对象列表(例如:)传递List<Human>给此片段的方法.我试过Bundle()但却找不到合适的方法.
我正在尝试显示通过存储的相机意图(触发内置相机应用程序)捕获的图片external SD-card.
文件路径和文件名存储在String变量中'mCurrentPhotoPath'.
我已经验证捕获的图像存储在'mCurrentPhotoPath'使用ES File Explorerapp 指定的位置,但BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions)始终返回FileNotFoundException.这是我存储捕获图像的代码:
private void addPicToGallery() {
File f = new File(mCurrentPhotoPath);
//for debug purpose only
Log.i(MYTAG, "value of mCurrentPhotoPath in addPicToGallery: " +mCurrentPhotoPath);
Log.i(MYTAG, "value of f in addPicToGallery: " +f);
Uri contentUri = Uri.fromFile(f);
//for debug only
Log.i(MYTAG, "value of contentUri in addPicToGallery: " +contentUri);
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
}
Run Code Online (Sandbox Code Playgroud)
解码缩放图像的代码,用于显示ImageView:
private void setFullImageFromFilePath() {
Log.i(MYTAG, …Run Code Online (Sandbox Code Playgroud)