logo
Tags down

shadow

how can I move views on the right direction in constrainlayout


By : zhhliu
Date : October 17 2020, 06:10 PM
To fix the issue you can do Wrap the views with another Viewgroup (say ConstraintLayout again) and set app:layout_constraintStart_toStartOf="parent" and app:layout_constraintEnd_toEndOf="parent" as constraints to this viewgroup. Said view will then be centered horizontally.
Edit: The code
code :
<android.support.constraint.ConstraintLayout android:layout_height="wrap_content" android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">

    <ImageView

        android:id="@+id/articleImage"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_margin="8dp"
        app:layout_constraintDimensionRatio="16:9"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline4"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <TextView
        android:id="@+id/articleAuthor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:gravity="start"
        android:text="article_author"
        android:textSize="12sp"
        app:layout_constraintEnd_toStartOf="@+id/articleImage"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <TextView
        android:id="@+id/articleTitle"
        android:layout_width="0dp"

        android:layout_height="wrap_content"

        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"

        android:layout_marginEnd="8dp"

        android:layout_marginBottom="8dp"

        android:text="article_title"

        android:textSize="12sp"


        app:layout_constraintEnd_toStartOf="@+id/guideline4"

        app:layout_constraintHorizontal_bias="0"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toBottomOf="@+id/articleAuthor" />


    <TextView

        android:id="@+id/articleTime"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginStart="8dp"

        android:layout_marginLeft="8dp"

        android:layout_marginTop="8dp"

        android:layout_marginBottom="8dp"

        android:text="Article Time"

        android:textSize="18sp"

        app:layout_constraintEnd_toStartOf="@+id/articleFavorite"

        app:layout_constraintHorizontal_bias="0"

        app:layout_constraintHorizontal_chainStyle="packed"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toBottomOf="@+id/articleTitle" />


    <ImageButton

        android:id="@+id/articleFavorite"
        android:layout_width="32dp"
        android:layout_height="32dp"

        android:background="@color/"

        android:src="@drawable/"

        app:layout_constraintBottom_toBottomOf="@+id/articleTime"

        app:layout_constraintEnd_toStartOf="@+id/articleShare"
        app:layout_constraintStart_toEndOf="@+id/articleTime"
        app:layout_constraintTop_toTopOf="@+id/articleTime" />


    <ImageButton

        android:id="@+id/articleShare"
        android:layout_width="32dp"
        android:layout_height="32dp"

        android:layout_marginEnd="8dp"

        android:layout_marginRight="8dp"

        android:background="@color/"

        android:contentDescription="TODO"

        android:src="@drawable/"

        app:layout_constraintBottom_toBottomOf="@+id/articleTime"

        app:layout_constraintEnd_toStartOf="@+id/guideline4"
        app:layout_constraintStart_toEndOf="@+id/articleFavorite"
        app:layout_constraintTop_toTopOf="@+id/articleTime" />


    <android.support.constraint.Guideline

        android:id="@+id/guideline4"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.6" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.Guideline
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.55"
    android:id="@+id/guideline"/>
<ImageView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@id/guideline"
    app:layout_constraintDimensionRatio="16:9"
    android:layout_margin="16dp"
    android:id="@+id/imageView"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    android:id="@+id/mainTextView"
    android:layout_marginStart="25dp"
    android:layout_marginTop="10dp"
    android:text="Placeholder"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@id/mainTextView"
    app:layout_constraintStart_toStartOf="@id/mainTextView"
    android:layout_marginTop="5dp"
    android:text="Secondary"
    android:id="@+id/secondaryTextView"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@id/secondaryTextView"
    app:layout_constraintStart_toStartOf="@id/mainTextView"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="5dp"
    android:text="Tertiary"
    android:id="@+id/tertiaryTextView"/>

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="@id/tertiaryTextView"
    app:layout_constraintBottom_toBottomOf="@id/tertiaryTextView"
    app:layout_constraintStart_toEndOf="@id/tertiaryTextView"
    android:layout_marginStart="15dp"
    android:id="@+id/firstButton"/>
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="@id/firstButton"
    app:layout_constraintBottom_toBottomOf="@id/firstButton"
    app:layout_constraintStart_toEndOf="@id/firstButton"
    android:layout_marginStart="15dp"
    android:id="@+id/secondButton"/>


Share : facebook icon twitter icon

How do I move an object in one direction with a single keypress until the direction is changed?


By : mgsa143
Date : March 29 2020, 07:55 AM
Hope this helps When I start the program and press the first key the program freezes. Can anyone tell me why this doesn't work and give me a possible solution to my problem? , it could be something like this
code :
speed = (0, 0)

While True:

    # --- events ---

    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                speed = (0, -50)
            elif event.key == pygame.K_DOWN:
                speed = (0, 50)
            if event.key == pygame.K_LEFT:
                speed = (-50, 0)
            if event.key == pygame.K_RIGHT:
                speed = (50, 0)

    # --- all updates (without draws) ---

    schlange.move(speed[0], speed[1])

    # --- all draws (without updates) ---

    # ...

Why does player sometimes move in wrong direction when switching direction


By : ravisankar
Date : March 29 2020, 07:55 AM
will help you Your acceleration method is a bit obscure (pun intended), here are 2 suggestions:
code :
    Player *p = t->player;

    /* X movement */
    if (p->speed & (BMXSPEED * 3) == BMXSPEED)
        p->xspeed += (p->xspeedMax - fabs(p->xspeed)) / p->xspeedMax;
    else
    if (p->speed & (BMXSPEED * 3) == BMXSPEED << 1)
        p->xspeed -= (p->xspeedMax - fabs(p->xspeed)) / p->xspeedMax;
    else
        p->xspeed -= copysign((p->xspeedMin - fabs(p->xspeed)) / p->xspeedMax, p->xspeed);

    /* Y movement */
    if (p->speed & (BMYSPEED * 3) == BMYSPEED)
        p->yspeed += (p->yspeedMax - fabs(p->yspeed)) / p->yspeedMax;
    else
    if (p->speed & (BMYSPEED * 3) == BMYSPEED << 1)
        p->yspeed -= (p->yspeedMax - fabs(p->yspeed)) / p->yspeedMax;
    else
        p->yspeed -= copysign((p->yspeedMin - fabs(p->yspeed)) / p->yspeedMax, p->yspeed);

ConstrainLayout not able to align two views


By : Hardeep Singh
Date : March 29 2020, 07:55 AM
like below fixes the issue Your constraints on "Tendulkar" are causing the TextView to be centered. You want to align the left side of that TextView with the left side of "Sachin" as follows:
code :
<TextView
    android:id="@+id/textView2"
    style="@style/SmallGray"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Tendulkar"
    app:layout_constraintLeft_toLeftOf="@id/textView4"
    app:layout_constraintBaseline_toBaselineOf="@+id/tvLastName"/>

GeoDjango: Move a coordinate a fixed distance in a given direction (e.g. move a point east by one mile)


By : user1569938
Date : March 29 2020, 07:55 AM
it helps some times You can accomplish this using the Geod class of pyproj.
code :
from pyproj import Geod
geoid = Geod(ellps='WGS84')

def add_distance(lat, lng, az, dist):
    lng_new, lat_new, return_az = geoid.fwd(lon, lat, az, dist)
    return lat_new, lng_new
from django.contrib.gis.geos import Point

def move_point_mile_east(point):
    dist = 1609.34
    lat, lng = add_distance(point.y, point.x, 90, dist)
    return Point(lng, lat)

How to add a percentage margin between two views in ConstrainLayout


By : M. Pijush
Date : September 27 2020, 10:00 PM
I think the issue was by ths following , You can use a element in your layout to achieve this. Let's say you want 10% left/right margin and a 20% gap between two views that fill the rest of the space:
code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/startMargin"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.1"/>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/endMargin"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.9"/>

    <View
        android:id="@+id/first"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#fac"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@id/startMargin"
        app:layout_constraintEnd_toStartOf="@id/space"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <Space
        android:id="@+id/space"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@id/first"
        app:layout_constraintEnd_toStartOf="@id/second"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintWidth_percent="0.2"/>

    <View
        android:id="@+id/second"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#caf"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@id/space"
        app:layout_constraintEnd_toStartOf="@id/endMargin"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Related Posts Related Posts :
  • Android CameraX doesn't show anything
  • XML constraint layout: Elements placed on top of each other, fix?
  • Flutter - dynamic height on a tab
  • With Scoped Storage introduced in Android Q, how am I supposed to develop a file manager app?
  • Can't resolve symbol android.support.v4.util.Pools in react-native-gesture-handler
  • Jetpack Compose: Could not set unknown property 'useIR'
  • SQLiteException: file is not a database while upgrading sqlcipher version from 3 to 4
  • What are best practices of implementing user login session in android application?
  • Button text not aligned center vertically in react native
  • "flutter (os error: no address associated with hostname, errno = 7)" only for android
  • How to catch platformException in flutter/dart?
  • Unable to connect to ADB
  • How can I test In-app updates in Android?
  • How to apply multiple generics in a function using Kotlin
  • Gradle DSL method not found: 'kapt()'
  • Android ADB: How to push multiple files, into an emulator?
  • How to run a multiple AND query with Android Room?
  • How do i fix the getting null location value from FusedLocationProviderClient in android
  • Which ad formats uses tinder?
  • How to perform delete api in retrofit
  • AWS AppSync Error - AWSMobileClientStore.get(String) on null object reference
  • How to make back button on WebView work in onBackPressed?
  • Circular reference error in firebase with R8
  • Send Intent From Activity To Fragment
  • findViewById with PhotoView library problem
  • Removing the bottom Padding from a TextView while using HTML Format
  • Defining resValue conditionally in build.gradle
  • Is there another solutions instead of nested Recyclerview
  • Firebase + Flutter - Cloud functions onCall result in "unauthenticated" error from Android app
  • How to change textview text on cardview click?
  • App crash on opening document for some devices
  • How to fix Android compatibility warnings
  • Can't override android color resources
  • How add menu item's only for debug build type
  • RecyclerView with CardView Items, notifyItemChanged and shadow problem
  • Start activity without click on push notification's item
  • Checking if kapt uses incremental annotation processing
  • Show locations near user's location
  • How to hide a sub-mesh from SFB file in ArCore Android
  • There is always a default background on TextInputLayout in Android
  • 'List' is abstract; cannot be instantiated
  • A list in a list?
  • Wrong date returned from Location.getTime after 6 April 2019 (week number rollover)
  • socket connection using retrofit in Kotlin
  • Build Command Failed for CMake
  • Navigating between pages
  • Android : Support in-app updates result getting cancelled
  • What will cause Modifier 'abstract' not allowed here in RoomDatabase file using Android Studio?
  • Layout Expression - Ternary Operation for drawable value
  • How to have an Android Button with only a bottom border?
  • Actions on Google - Unable to test intent for app action on Android
  • Required single selection on MaterialButtonToggleGroup
  • AAPT: error: attribute android:forceDarkAllowed not found
  • Stop reloading previous fragment by using Navigation architecure
  • How to close the SimpleDialog in flutter after choosing an option
  • Sniffing SSL packets using Wireshark
  • Integrating google map api key in my android project
  • How to fix TextView position when text in it changes
  • Prevent 3rd party libraries to get my push notifications
  • Android bluetooth printer app works fine in debug mode but doesn't work in release mode
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk