小编JDe*_*ais的帖子

在ConstraintLayout中使用<include>和<merge>

我在使用标签<include><merge>ConstraintLayout内部时遇到问题.

我想创建一个平面视图层次结构(因此Constraints),但仍然有可重用的元素.所以我<include>在我的布局和<merge>包含的布局中使用以避免嵌套布局(特别是避免嵌套的ConstraintLayouts)

所以我写了这样的:父布局

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/review_1"
        layout="@layout/view_movie_note"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/review_2"/>

    <include
        layout="@layout/view_movie_note"
        android:id="@+id/review_2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginLeft="7dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/review_1"
        app:layout_constraintRight_toRightOf="parent"
        />

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

这个view_movie_note:

<merge>

    <TextView
        android:id="@+id/note_origin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginStart="5dp"
        app:layout_constraintStart_toStartOf="@+id/cardView2"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="5dp" />


    <android.support.v7.widget.CardView
        android:id="@+id/five_star_view_container"
        android:layout_width="0dp"
        android:layout_height="52dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="10dp"
        android:elevation="3dp"
        app:cardUseCompatPadding="true"
        app:contentPaddingTop="22dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_min="52dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/note_origin">

        <FiveStarsView
            android:id="@+id/five_star_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" />

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/cardView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        app:cardBackgroundColor="@color/colorPrimary"
        app:contentPaddingLeft="15dp"
        app:contentPaddingRight="15dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/note_origin">

        <TextView
            android:id="@+id/grade" …
Run Code Online (Sandbox Code Playgroud)

android android-layout viewgroup android-constraintlayout

28
推荐指数
2
解决办法
7273
查看次数

从不调用google api客户端回调

我正在尝试使用谷歌服务API获取最后一个已知位置,但在我构建GoogleApiClient后,没有触发任何回调方法.

我的活动看起来像这样:

public class MainActivity extends Activity implements FragmentObserver, SessionSpotListObserver,
                                                        ConnectionCallbacks, OnConnectionFailedListener{

//Objects used for the location API
    private Location mLastLocation;
    private GoogleApiClient mGoogleApiClient;
    // Request code to use when launching the resolution activity
    private static final int REQUEST_RESOLVE_ERROR = 1001;
    // Unique tag for the error dialog fragment
    private static final String DIALOG_ERROR = "dialog_error";
    // Bool to track whether the app is already resolving an error
    private boolean mResolvingError = false;
    public static final String STATE_RESOLVING_ERROR = "resolving_state"; …
Run Code Online (Sandbox Code Playgroud)

android google-api-client

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

AppBarLayout并不总是在向下滚动时重新输入

我在CoordinatorLayout和RecyclerView内使用AppBarLayout,CollapsingToolbarLayout创建了折叠式透明搜索栏。让recyclerView出现在appBarLayout的后面而不是在它的下面是很多技巧。但正在工作。我的问题是,有时候,当我向下滚动时,应用程序栏不会重新进入。我只是在屏幕外不可见。这是我的布局:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:expandedTitleMarginBottom="88dp">

<android.support.v7.widget.RecyclerView
    android:id="@+id/services_recycler_view"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:behavior_overlapTop="88dp">

</android.support.v7.widget.RecyclerView>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:background="@color/color_transparent"
        app:elevation="0dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways"
        android:fitsSystemWindows="false">

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Search Location or Service"
    android:id="@+id/button_search_bar"/>



    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

解决不重新进入问题的任何帮助将是巨大的。

另一个问题是,因为我使用的app:behavior_overlapTop="88dp"是使recyclerView出现在应用程序栏的后面,所以整个滚动有些奇怪:它首先滚动appBar,然后滚动回收器视图。任何更好的解决方案都是值得欢迎的。

编辑: 我意识到AppBar确实在向下滚动时重新输入,但是是不可见的(我可以单击它,我只是看不到它)。我想我会分享这个新线索=)

android scroll material-design android-recyclerview android-appbarlayout

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

使用导航组件时 DialogFragment 不会关闭

我是导航组件的新手,我想将它与自定义对话框片段一起使用。

这是我的 nav_graph

    <dialog
        android:id="@+id/enterAisleNameDialog"
        android:name="com.cbplus.scan_product.view.EnterAisleNameDialog"
        android:label="EnterAisleNameDialog">
    <action
            android:id="@+id/action_enterAisleNameDialog_to_scanSummaryFragment"
            app:destination="@id/scanSummaryFragment"/>
</dialog>
Run Code Online (Sandbox Code Playgroud)

在我的 Kotlin Activity 中,我可以使用以下方法轻松显示对话框:

navController?.navigate(R.id.action_validateProductExpFragment_to_enterAisleNameDialog)
Run Code Online (Sandbox Code Playgroud)

然后,当在对话框上完成操作时,我调用:

navController?.navigate(R.id.action_enterAisleNameDialog_to_scanSummaryFragment)
Run Code Online (Sandbox Code Playgroud)

但是这里下一个片段显示在不会消失的对话框片段下方。

我在我的实现中遗漏了什么?

我可以调用dismiss()对话框,但导航控制器没有这样做似乎很奇怪。

navigation android dialog android-jetpack

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