Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:05:13+00:00 2026-06-03T22:05:13+00:00

i have a problem with an RelativeLayout. I try to create the following with

  • 0

i have a problem with an RelativeLayout. I try to create the following with Java-Code:

<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<CheckBox
    android:id="@+id/CheckBox01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:clickable="false" />

<TextView
    android:id="@+id/TextView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:text="TEXT here"
    android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>

The XML from above creates the look i wanna have. Now I’m trying to do this with Java-Code:

// First Child: TextView
text = new TextView(context);
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
text.setText(contentText);
text.setTextSize(20);

// Layout-Info for text
RelativeLayout.LayoutParams text_relativeParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
text_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
text_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

// Add text to layout:
this.addView(text, text_relativeParams);
// Checkbox
checkbox = new CheckBox(context);
checkbox.setClickable(false);
checkbox.setChecked(reachable);
checkbox.setBackgroundColor(Color.BLUE);
checkbox.setText("");
checkbox.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

// Layout-Info for Checkbox
RelativeLayout.LayoutParams checkbox_relativeParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
checkbox_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
checkbox_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

// Adding Checkbox to layout:
this.addView(checkbox);

The Java-Code from above should do the same as the XML. But there is a little difference between should an do. The Checkbox appears on the left side. How do i move the Checkbox to the right? (this is a derived class from RelativeLayout, the code is in the Constructor)

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:05:15+00:00Added an answer on June 3, 2026 at 10:05 pm

    Remove this line of code

    checkbox.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    

    Set the layout params of checkbox with checkbox_relativeParams

    RelativeLayout.LayoutParams checkbox_relativeParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    checkbox_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    checkbox_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    this.addView(checkbox, checkbox_relativeParams);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem with my scrollview... my xml: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=wrap_content android:layout_height=wrap_content>
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
I have a weird problem. While running my Android application, I receive Exception: java.lang.ClassCastException:
I have a problem with two Textviews on the same height in a RelativeLayout
I have a problem with a RelativeLayout containing two TextView s and a ImageView
I'm having the following problem: I have a ListView and I get the layout
i have a big problem with a layout in my Android Application. I have
I have some problem with RelativeLayout positioning: Now I have this: http://dl.dropbox.com/u/18411570/now.png And I
<?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/messageLayout android:layout_width=fill_parent android:layout_height=wrap_content> <ImageView android:id=@+id/messageSender android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginRight=10dp android:layout_marginLeft=10dp
I'm having a problem with my android program. I have about every thing working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.