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 7841467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:06:25+00:00 2026-06-02T16:06:25+00:00

I have this main.xml : <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent > <ImageView

  • 0

I have this main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher"/>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/white"
        android:orientation="horizontal" >   
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
             android:background="@drawable/barslide" 
             android:layout_marginLeft="500dp"/>
    </LinearLayout>
</FrameLayout>

I want to create the same UI like in main.xml in java code. I try to code it but it doesn’t work, it’s not same as the xml. Here is the code:

void createUI(){

    LayoutParams params1 = new FrameLayout
    (LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);

    LayoutParams params2 = new android.widget.FrameLayout.LayoutParams(
    android.widget.FrameLayout.LayoutParams.FILL_PARENT,
android.widget.FrameLayout.LayoutParams.FILL_PARENT,
Gravity.BOTTOM);

FrameLayout f1 = new FrameLayout(this);
f1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

LinearLayout l2 = new LinearLayout(this);
l2.setOrientation(LinearLayout.HORIZONTAL);
l2.setLayoutParams(params2);

view1 = new page1(getBaseContext());
view360 = view1.img1(getBaseContext());
view360.setBackgroundDrawable(getResources().getDrawable(R.drawable.black1));
view360.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

slidebar = view1.img3(getBaseContext());
slidebar.setBackgroundResource(R.drawable.barslide);
slidebar.setLayoutParams(new LinearLayout.LayoutParams(300, LayoutParams.WRAP_CONTENT,Gravity.BOTTOM));


f1.addView(view360);
f1.addView(l2);
l2.addView(slidebar);

addContentView(f1, params1);
}
  • 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-02T16:06:28+00:00Added an answer on June 2, 2026 at 4:06 pm

    Your code doesn’t quite replicate the xml layout(this was to big for a comment):

                // replace THIS(from the constructors) with your context reference
        FrameLayout fl = new FrameLayout(this);
        fl.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT));
        ImageView imv1 = new ImageView(this); // the first ImageView
        imv1.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT));
        imv1.setImageResource(R.drawable.ic_launcher);
        fl.addView(imv1);
        LinearLayout ll = new LinearLayout(this);
        FrameLayout.LayoutParams llp = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        llp.gravity = Gravity.BOTTOM;
        ll.setLayoutParams(llp);
        ll.setBackgroundColor(Color.WHITE);
        ImageView imv2 = new ImageView(this); // the second ImageView
        DisplayMetrics metrics = getResources().getDisplayMetrics();
        float width = 300f;     
        int pWidth = (int) (metrics.density * width + 0.5f);
        LinearLayout.LayoutParams imvlp = new LinearLayout.LayoutParams(pWidth,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        float margin = 500f;
        int pMargin = (int) (metrics.density * margin + 0.5f);
        imvlp.leftMargin = pMargin;
        imv2.setLayoutParams(imvlp);
        imv2.setBackgroundResource(R.drawable.food_image1);
        ll.addView(imv2);
        fl.addView(ll);
    

    You’ll have to modify it to use your object page1(I don’t know exactly what are you trying to do there).
    Also, are you sure you have to use the addContentView()(maybe setContentView?) method?(This method will add the views to the already present layout)

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

Sidebar

Related Questions

I have the following layout in main.xml : <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have a tabLayout where main.xml: <?xml version=1.0 encoding=utf-8?> <TabHost xmlns:android=http://schemas.android.com/apk/res/android android:id=@android:id/tabhost android:layout_width=fill_parent android:layout_height=fill_parent>
I have this main.xml file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/background
So my main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical
I have the following application.xml <?xml version=1.0 encoding=utf-8?> <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.currency.mobile.android> <uses-permission android:name=android.permission.INTERNET/> <application
I have a main activity with this layout file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have this JSF table: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I just can't figure it out. I have this shape in res/drawable/start_light.xml <?xml version=1.0
I have created bg3.9.png image following this tutorial http://developer.android.com/guide/developing/tools/draw9patch.html but when i put it
I have a custom listView. The main layout xml is something like this: <?xml

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.