始终将MaterialShowcaseView的“GOT IT”按钮放在屏幕的左下角

时间:2017-07-25 13:38:39

标签: android

我正在使用以下库:https://github.com/deano2390/MaterialShowcaseView 我一直试图找到一种方法(连续2天!)始终将“GOT IT”按钮放在屏幕的左下角。我如何简单有效地实现这一目标?

我会立即接受工作答复。如你所见,我有一直接受答案的历史。

enter image description here

有了Osama的回答,我收到了错误:

com.example.me.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.me.myapplication, PID: 4445
    java.lang.IllegalStateException: Cannot start this animator on a detached view!
        at android.view.RenderNode.addAnimator(RenderNode.java:812)
        at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:300)
        at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:282)
        at android.animation.RevealAnimator.<init>(RevealAnimator.java:37)
        at android.view.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:55)
        at uk.co.deanwild.materialshowcaseview.CircularRevealAnimationFactory.animateInView(CircularRevealAnimationFactory.java:29)
        at uk.co.deanwild.materialshowcaseview.MaterialShowcaseView.animateIn(MaterialShowcaseView.java:825)
        at uk.co.deanwild.materialshowcaseview.MaterialShowcaseView$1.run(MaterialShowcaseView.java:794)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

MainActivity:

package com.example.me.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // single example
        new MaterialShowcaseView.Builder(this)
                .setTarget(findViewById(R.id.hi))
                .setDismissText("GOT IT")
                .setContentText("This is some amazing feature you should know about! Indeed, this is just an example of a bug that can be easily fixed!")
                .show();

    }
}

activity_main.xml中:

<?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:context="com.example.me.myapplication.MainActivity">

    <TextView
        android:id="@+id/hi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.419" />

</android.support.constraint.ConstraintLayout>

2 个答案:

答案 0 :(得分:0)

此lib基于ShowcaseView,请查看它。

您也可以转到图书馆模块的showcase_content.xml,然后将{GOT IT“tv_dismiss TextView放入RelativeLayout这样的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content_box"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    android:weightSum="1">

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:paddingLeft="5dp"
        android:textColor="@android:color/white"
        android:textSize="30dp" />

    <TextView
        android:id="@+id/tv_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:textColor="@android:color/white"
        android:textSize="20dp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_dismiss"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:background="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:layout_alignParentBottom="true"
            android:paddingBottom="10dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="10dp"
            android:textColor="@android:color/white"
            android:textSize="22dp"
            android:visibility="gone" />
    </RelativeLayout>

</LinearLayout>

转到MaterialShowcaseView.java并清空applyLayoutParams()方法并将setDelay更新为1000 enter image description here

答案 1 :(得分:0)

在构建器中,添加以下代码。

in