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

  • SEARCH
  • Home
  • 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 8495111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:28:48+00:00 2026-06-10T23:28:48+00:00

I am tryin to add ten relativeLayouts dynamically by inflating the xml , but

  • 0

I am tryin to add ten relativeLayouts dynamically by inflating the xml , but the relative layouts getting overlapped. how to change the margins of the inflating xml dynamically via code.

Below is the code reuse.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/aaa"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
     >

    <ImageView
        android:id="@+id/image"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="5dp"
        android:scaleType="centerCrop"
        android:src="@drawable/ballaya" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="12dp"
        android:layout_weight="1"
        android:text="Srimannarayana earns Rs 8.65 cr on day 1"
        android:textColor="#FFFFFF"
        android:textSize="11sp"
        android:textStyle="bold" />

    <View
        android:id="@+id/seperator"
        android:layout_width="fill_parent"
        android:layout_height="0.5dp"
        android:layout_below="@+id/image"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:background="#FFFFFF" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dp"
        android:src="@drawable/popover_bg_rghtarw" />

</RelativeLayout>

code of item.xml

<?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"
    android:background="#06516E" >

    <RelativeLayout 
     android:layout_width="fill_parent"
    android:layout_height="20dp" 
    android:background="#49C7F9">
         <TextView
            android:id="@+id/HeadLines"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"

            android:text="Latest News"
            android:textColor="#FFFFFF"
            android:textSize="12sp"
            android:textStyle="bold" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/newsLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="30dp" >

    </RelativeLayout>
</RelativeLayout>

Java Code

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        super.onCreate(savedInstanceState);
        setContentView(R.layout.item);

        newsLayout =(RelativeLayout)findViewById(R.id.newsLayout);

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        RelativeLayout row[] = new RelativeLayout[10];
         TextView text[]= new TextView[10];
        for(int i=0;i<10;i++){

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

       row[i] = (RelativeLayout) inflater.inflate(R.layout.reuse,null);
       params.setMargins(0, 50, 0, 0);
        newsLayout.addView(row[i],params);

         text[i]= (TextView) row[i].findViewById(R.id.text);
        text[i].setText("AAAAAAA");


        }
  • 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-10T23:28:49+00:00Added an answer on June 10, 2026 at 11:28 pm

    You can use LinearLayout instead of RelativeLayout for newsLayout and make the orientation as VERTICAL.

    And instead of newsLayout =(RelativeLayout)findViewById(R.id.newsLayout);
    write: newsLayout =(LinearLayout)findViewById(R.id.newsLayout);

    And rest of the code will be as it is.

    This will solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying add roles to a drop dropdown box but im getting the error
I am having a hard time tryin to add an if statement to check
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a blank sample app for a rails tutorial to GitHub, but
Trying to add a class object into a List using reflection, but when invoking
I'm new to ocaml and tryin to write a continuation passing style function but
I am tryin to add data to my list object. For a string, I
I'm tryin to scan an entire process memory but no success... What I'm doing
I am trying add value to a mutlidimensional array but I am slightly confused

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.