Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – Set view’s direction to the opposite direction of its layout

Posted on November 14, 2022

Solution 1 :

You can use this code:

if(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)

to determine wether the LayoutDirection is RTL or LTR and set the position of the Checkbox programmatically.

Here is an example:

layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns_android="http://schemas.android.com/apk/res/android"
    android_layout_height="match_parent"
    android_layout_width="match_parent"
    android_background="#00CCCC"
    >
    <RelativeLayout
        android_id="@+id/parentRelativeLayout"
        android_layout_centerInParent="true"
        android_layout_width="match_parent"
        android_layout_height="wrap_content"
        android_layout_margin="5dp">
        <CheckBox
            android_layout_alignParentRight="true"
            android_id="@+id/checkbox"
            android_layout_width="wrap_content"
            android_layout_height="wrap_content"
            android_text="Hide...">
        </CheckBox>
    </RelativeLayout>

</RelativeLayout>

MainActivity.java:

package com.example.androidlayout;

import androidx.appcompat.app.AppCompatActivity;

import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {
    CheckBox checkbox;
    RelativeLayout parent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        checkbox = (CheckBox) findViewById(R.id.checkbox);
        parent = (RelativeLayout) findViewById(R.id.parentRelativeLayout);

        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) checkbox.getLayoutParams();
        Configuration config = getResources().getConfiguration();
        if(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        }else{
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }
        checkbox.setLayoutParams(layoutParams);

    }
}

Problem :

I Have a Relative layout and its direction based on app language (there are two directions: LTR and RTL), and I have one view (CheckBox) inside that layout.
now I want to make the Checbox direction to the opposite direction to its layout.

Any advice?

Edit

enter image description here
when be the layout direction is LTR I want to make this checkbox direction is RTL, as well when be the layout direction is RTL I want to make this checkbox direction is LTR.

Comments

Comment posted by Mbuodile Obiosio

You should add the code of what you’re trying to do and possibly an image to indicate

READ  [ANSWERED] permissions - Update Android Things app via USB and package installer
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress