Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget Using Constraint Layout

I am Trying to use constraintLayout for my widget but it gave me an error at line #0(Doesn't xml start at line 1?).

Here is the code:

<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"
    android:background="#FFF"
    android:padding="@dimen/widget_margin">


    <TextView
        android:id="@+id/appwidget_text"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_margin="8dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="#09C"
        android:text="@string/appwidget_text"
        android:textColor="#ffffff"
        android:textSize="24sp"
        android:textStyle="bold|italic"
        android:gravity="center"
        app:layout_constraintBottom_toTopOf="@+id/split2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:contentDescription="@string/appwidget_text"/>

    <Button
        android:id="@+id/flip"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="8dp"
        android:text="@string/show_answer"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/split"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/split2" />

    <Button
        android:id="@+id/next"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:text="@string/next_question"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/split"
        app:layout_constraintTop_toBottomOf="@+id/split2" />

    <android.support.constraint.Guideline
        android:id="@+id/split"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />

    <android.support.constraint.Guideline
        android:id="@+id/split2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.75" />

</android.support.constraint.ConstraintLayout>

Error:

Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout

Note: I tried it using Linear layout and it worked, but I prefer to do it using constraintLayout.

like image 249
Mohammad Tabbara Avatar asked Dec 05 '17 18:12

Mohammad Tabbara


People also ask

What is constraint layout used for?

A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread). As such, we are planning on enriching its API and capabilities over time.

Should I use constraint layout or linear layout?

Well, each layout has its own benefits but when it comes to complex, dynamic and responsive views you should always choose Constraint Layout. Constraint Layout was added to Android Studio 2.2 in 2016 and it became the default layout of Android Studio because of its simplicity and ease of creating complex layouts.

What is Androidx ConstraintLayout widget ConstraintLayout?

GitHub - androidx/constraintlayout: ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way. Skip to content Toggle navigation.

Is ConstraintLayout faster than Linearlayout?

More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout.


1 Answers

There are only a few View classes that you can use in an app widget. ConstraintLayout is not among them.

like image 159
CommonsWare Avatar answered Nov 11 '22 13:11

CommonsWare