Skip to content Skip to sidebar Skip to footer

How To Fix This Margin Gap?

I am creating an Faq page using TextViews, So the textviews become visible and hide automatically when clicked, but this was overlapping the upcoming question so I researched and f

Solution 1:

Can you print the xml ? try with "wrap_content" in parent layout


Solution 2:

You can use Cardview to encapsulate your Faq element :

https://developer.android.com/guide/topics/ui/layout/cardview

Then change the visibility of the component that you want to hide as gone and set a listner to change the visibility if the textView (or your cardView ) is clicked

Textview label = (TextView ) myPosts.findViewById(R.id.cancel);
    cancelButton.setOnClickListener(view->{
        if(newPostCard.getVisibility() == View.VISIBLE){
            TransitionManager.beginDelayedTransition(cardView,
                    new AutoTransition());
            newPostCard.setVisibility(View.GONE);
            newPostButton.setVisibility(View.VISIBLE);


        }
        else{
            TransitionManager.beginDelayedTransition(cardView,
                    new AutoTransition());
            newPostCard.setVisibility(View.VISIBLE);
            newPostButton.setVisibility(View.GONE);


        }
    });

Solution 3:

The way I got around to this problem was to add a linear layout to the questions and answer fields. here is the xml code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    android:background="@android:color/holo_orange_dark"
    tools:context=".faq">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="300dp"
        tools:context=".faq">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="@string/Welcome"
            android:textColor="#000000"
            android:textColorHighlight="#000000"
            android:textColorHint="#000000"
            android:textSize="36sp"
            app:fontFamily="@font/racing_sans_one"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/frequentlyaskedquestions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/faqs"
            android:textColor="#FFFFFF"
            android:textColorHighlight="#FFFFFF"
            android:textColorHint="#FFFFFF"
            android:textColorLink="#FFFFFF"
            android:textSize="18sp"
            app:fontFamily="@font/racing_sans_one"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView" />

        <TextView
            android:id="@+id/clickonthem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="@string/clickonthem"
            android:textColor="#FFFFFF"
            android:textColorHighlight="#FFFFFF"
            android:textColorHint="#FFFFFF"
            android:textColorLink="#FFFFFF"
            android:textSize="18sp"
            app:fontFamily="@font/racing_sans_one"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/frequentlyaskedquestions" />

        <LinearLayout
            android:layout_width="409dp"
            android:layout_height="294dp"
            android:layout_marginTop="28dp"
            android:orientation="vertical"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/clickonthem">

            <TextView
                android:id="@+id/faq1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:clickable="true"
                android:focusable="true"
                android:text="@string/q1"
                android:textColor="#000000"
                android:textColorHighlight="#000000"
                android:textColorHint="#000000"
                android:textSize="18sp"
                android:textStyle="bold|italic" />

            <TextView
                android:id="@+id/ans"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:layout_marginRight="20dp"
                android:text="@string/a1"
                android:textColor="#000000"
                android:textColorHighlight="#000000"
                android:textColorHint="#000000"
                android:textColorLink="#000000"
                android:textSize="18sp"
                android:textStyle="bold|italic"
                android:visibility="gone" />

            <TextView
                android:id="@+id/faq2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:layout_marginRight="20dp"
                android:clickable="true"
                android:focusable="true"
                android:text="@string/q2"
                android:textColor="#000000"
                android:textColorHighlight="#000000"
                android:textColorHint="#000000"
                android:textSize="18sp"
                android:textStyle="bold|italic" />

            <TextView
                android:id="@+id/ans2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:layout_marginRight="20dp"
                android:text="@string/a2"
                android:textColor="#000000"
                android:textColorHighlight="#000000"
                android:textColorHint="#000000"
                android:textColorLink="#000000"
                android:textSize="18sp"
                android:textStyle="bold|italic"
                android:visibility="gone" />
        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Post a Comment for "How To Fix This Margin Gap?"