Guide to positioning the layout inflater on the right side

I am facing an issue with the layout inflater where the inflated layout appears in the center of the page instead of the intended right corner placement. I have attempted to modify the gravity to right, but it did not resolve the problem.

Below is a snippet of my XML file:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="@color/primary"
android:orientation="vertical"
android:layout_alignParentEnd="true">
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:id="@+id/linshare"
    android:paddingTop="5dp"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="wrap_content"
        android:background="@drawable/share"
        android:layout_height="wrap_content" />
     <TextView
         android:layout_width="match_parent"
         android:text="Share"
         android:textSize="16sp"
         android:gravity="center"
         android:layout_gravity="center_horizontal"
         android:textColor="#FFFFFF"
         android:layout_height="match_parent" />
    </LinearLayout>
 <!-- More LinearLayouts here -->
   </RelativeLayout>

Here is a snippet of the code section:

private void menz() {
    LayoutInflater layoutInflater = LayoutInflater.from(Additionone.this);
    View promptView = layoutInflater.inflate(R.layout.menuinflate, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Additionone.this);
    alertDialogBuilder.setView(promptView);
    final LinearLayout share = (LinearLayout) promptView.findViewById(R.id.linshare);
    // Other LinearLayout assignments and onClickListeners below
}

Screenshot: https://i.sstatic.net/r5ZgI.png

Answer №1

To ensure proper alignment of your Alert Dialog Builder, make sure to set the appropriate Gravity for your view.

Try using

setGravity(Gravity.TOP | Gravity.RIGHT);

Take a look at this example for guidance.

Window window = alertDialogBuilder.getWindow();
window.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.TOP | Gravity.RIGHT);

Please note: You have the flexibility to adjust the Gravity settings of your Alert Dialog based on your preferences.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Storing geographic locations in a variable by inputting an address

Currently, I am working on a feature that allows users to input a location and then convert it into longitude and latitude coordinates. These coordinates will be stored in a variable called latlng instead of using preset coordinates. Right now, I have a fu ...

The fusion of PHP and HTML coding

I have been attempting to integrate some PHP code into a combination of HTML and I am facing some challenges. Below is the code I am working with: <?php $result = mysqli_query($db,"SELECT * FROM classes"); while($record = mysqli_fetch_array($result)) ...

Video refuses to play following application of ffmpeg retro effect

I am currently utilizing ffmpeg version 3.3.4 for Android. I have been running the following straightforward commands: ffmpeg -i input.mp4 -vf curves=vintage -c:a aac ouput.mp4 as well as ffmpeg -i input.mp4 -vf curves=vintage -c:a copy ouput.mp4 Unfortu ...

What is the best way to display various dialogs based on the specific button that is clicked?

Starting a new project, I foresee the need for numerous dialog boxes and modals. I've come up with some basic code that displays the dialog when a button is clicked and hides it when the cancel button is pressed. However, I'm facing the issue o ...

Implementing a watcher property in JavaScript to dynamically add a class to an element

I'm currently facing an issue where I need to apply a class to an element when a certain data property changes. My approach involves using a watcher to monitor the value change and adding a class through JavaScript, as demonstrated in the code snippet ...

Unable to add items to a shared list in an Android app

After extending Application and declaring a public ArrayList to hold data, I encountered an issue. Despite knowing that it should be implemented as a Singleton in Android, this was the only approach that worked for me. The problem : The error arises when ...

Utilizing Bootstrap for Centering Content Vertically and Horizontally

My login form is designed with a simple layout using Bootstrap 3.3.7 and a wrapper class div. However, when viewed on a full browser screen, the text boxes overlap the labels. How can I adjust it so that the default bootstrap behavior is applied to the for ...

What is the best way to add border-radius to an image while incorporating padding?

I am facing an issue with images that have white padding at the top and bottom. Please refer to the attached image. Whenever I try to apply the border-radius property to these images, the edges appear distorted. Is there a way to resolve this problem wit ...

What is the best way to specify attributes such as font size and padding for the mobile version in AMP for email?

I attempted to utilize media queries to create a responsive AMP email, but it seems that this feature is not supported in AMP. However, I discovered that you can define media="(max-width: 599px)" and media="(min-width: 600px)" for </amp-img>, but the ...

What consequences could occur in HTML if the main tag is not properly enclosed within the body tag?

Just starting out. While working with HTML, I experimented with placing the main tag outside of the body tag instead of nesting it inside as recommended by HTML5 standards. To my eye, both versions looked identical when I viewed the HTML file side by sid ...

Converting HTML content into Java objects

I have a log of messages from a messaging platform saved in HTML format. Each message is displayed as follows: <div class="message"> <div class="message_header"> <span class="user">User Name</span> <span class="meta"&g ...

Countdown malfunction: wrong date displayed

Utilizing the Countdownjs library in my project is resulting in an incorrect day count. Incorporating AngularJS, here is the custom directive I've implemented for the countdown: .directive('tempoPercorrido', function($interval){ ret ...

"Bootstrap4 - Troubleshooting the Issue of Multiple Carousels Not Function

I attempted to incorporate 2 Bootstrap 4 carousels onto a single page, but encountered issues with the functionality. I utilized this code on my page, however, the last element in the carousel does not cycle correctly. There is a delay of 3 transactions be ...

Tips for creating a 3D illusion by coding a div or object to rotate around another object or div

I have reached a technical and intellectual roadblock. The issue at hand is this: I need the text to encircle an image and create the illusion that it is moving in front of or behind the image, while keeping the image static. Currently, 1) the rotating te ...

Personalized validation messages with jQuery

I am currently working on a contact form using jQuery, but I am facing challenges in displaying my custom validation messages. Instead of showing the message I specified, it only displays a small popup with the generic message: "Please fill in the form". I ...

Obtaining template attributes in CKEditor: A guide

I have been working with the template plugin in CKEditor to load predefined templates. Each template is defined as follows: templates: [ { title: "Quickclick 1", image: "template1.png", description: "Quickclick 1 template", html_et: "& ...

Capture the selected hyperlink and show the corresponding page title in a designated box for reference

I want to track the links that users click on and display them in a box with an image and name of the page. Additionally, I would like to show how long the user spent on each page below the image. The images in the box should also be clickable links to the ...

Tips for aligning a SPAN in a navbar to the center

When attempting to center the middle span, the right span containing buttons shifts downward. I am trying to create a navigation bar with one link on the left, three links in the center, and two buttons on the right. While floating the elements on the left ...

Tips on how to dynamically update information with Angular

Looking to dynamically update data when a user selects an option from a dropdown menu using the Angular framework This is what I currently have: <div> <button type="button"> {{tests[0].test}} </button> <ul c ...

I need help figuring out how to showcase the following object in an Angular 5 HTML file

https://i.sstatic.net/XXm3W.png The console screenshot above shows an object with two values: users and tickers, each being an array of values. How can I display these values in an Angular 5 HTML template similar to the screenshot above? I attempted to ...