小编Mik*_*ike的帖子

使用<include>的ConstraintLayout问题

我想弄清楚为什么这不起作用.我只添加了两个<include>部分,ConstraintLayout并且布局不遵循我设置的任何约束.我想开始迁移到使用ConstraintLayout作为我去到布局,但像这样的事情不断推动我回RelativeLayoutLinearLayout.

这是顶级布局文件(ConstraintLayout),显示了一些不起作用的约束:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:layout_editor_absoluteY="81dp"
    tools:layout_editor_absoluteX="0dp">

    <include
        android:id="@+id/includeButton"
        layout="@layout/include_button_panel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <include
        android:id="@+id/includeText"
        layout="@layout/include_text_panel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

</android.support.constraint.ConstraintLayout
Run Code Online (Sandbox Code Playgroud)

这是第一个包含的布局(include_button_panel):

<?xml version="1.0" encoding="utf-8"?>
<merge
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:id="@+id/include_button_panel_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Touch me!" />

</merge>
Run Code Online (Sandbox Code Playgroud)

这是第二个包含的布局(include_text_panel):

<?xml version="1.0" encoding="utf-8"?>
<merge
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:id="@+id/include_text_panel_text"
        android:layout_width="wrap_content"
        android:background="#7986cb"
        android:layout_height="wrap_content"
        android:text="This is the text panel"
        android:textColor="@android:color/black"
        android:textSize="18sp" />
</merge>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

8
推荐指数
2
解决办法
2826
查看次数

从Content://和File:// URI获取轮换信息

我在用户选择图像时遇到问题,然后确定是否需要旋转图像.我以为我会很聪明,让我的所有处理都在Uris上运行,以便不知道图像来自哪里,但我看到的用于确定旋转的方法似乎需要Exif信息,这些信息不适用于内容: // Uri的类型.

问题:如果我的手柄是Uri,我怎么能确定图像是否需要旋转,而你不确定该图像来自哪里?

我这样做是为了得到一个图像:

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT,
               android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, INTENT_IMAGE_LOAD);
Run Code Online (Sandbox Code Playgroud)

...并且在onActivityResult()中我收到了Uri供以后处理.

        Uri imageUri = data.getData();

        // if the imageUri needs rotation, then fix it here (I know how to fix it).
        // ... but I think I need to use Exif data which I can't get from Content:// URI
        // hmmmmmmmm


        doMyProcessingOnUri(context, imageUri);
Run Code Online (Sandbox Code Playgroud)

显然Android 7.0已经改变了使用这样的Intent的一些方面,我认为这方面的大部分帮助都与7.0之前的版本有关.

android android-intent android-image

1
推荐指数
1
解决办法
439
查看次数