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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:05:49+00:00 2026-05-26T02:05:49+00:00

I am trying to implement a textview over an image in a framelayout at

  • 0

I am trying to implement a textview over an image in a framelayout at the center and bottom of the layout as it is seen here:

http://developer.android.com/resources/articles/layout-tricks-merge.html

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

<ImageView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:scaleType="center"
    android:src="@drawable/golden_gate" />

<TextView
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dip"
    android:layout_gravity="center_horizontal|bottom"

    android:padding="12dip"

    android:background="#AA000000"
    android:textColor="#ffffffff"

    android:text="Golden Gate" />

</FrameLayout>

I am trying to implement this programmatically but with no luck.. I always get the textview on the top left corner..can anyone help? Here is my code:

FrameLayout frameLay = new FrameLayout(MainScreen.this);                            
LayoutParams layoutParamsFrame = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

frameLay.setLayoutParams(layoutParamsFrame);

LinearLayout.LayoutParams layoutParamsImage= new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

ImageView imageView= new ImageView(MainScreen.this);
imageView.setImageResource(R.drawable.movie);   
imageView.setLayoutParams(layoutParamsImage);

TextView theText=new TextView(MainScreen.this);
theText.setText("GOLDEN Gate");
theText.setTextColor(Color.WHITE);                           
theText.setTypeface(Typeface.DEFAULT_BOLD); 

LayoutParams layoutParamsText= new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

theText.setLayoutParams(layoutParamsText);

theText.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);

frameLay.addView(theText);
frameLay.addView(imageView);
  • 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-05-26T02:05:50+00:00Added an answer on May 26, 2026 at 2:05 am

    All you need to do ias make the textview to fill the parent like

    LayoutParams layoutParamsText= new LayoutParams(LayoutParams.FILL__PARENT, 
            LayoutParams.FILL_PARENT); 
    

    When you set gravity to the textview, it mean you are telling the textview where to position its children. But since your textview only has the size of your text, the gravity wont show any difference. So just make the textview to fill the parent.

    But I think RelativeLayout is a lot more suitable for this than the FrameLayout. Using the RelativeLayout this is how it would look

    RelativeLayout rLayout = new RelativeLayout(this);
    LayoutParams rlParams = new LayoutParams(LayoutParams.FILL_PARENT
            ,LayoutParams.FILL_PARENT); 
    rLayout.setLayoutParams(rlParams);
    
    ImageView image= new ImageView(this); 
    image.setImageResource(R.drawable.icon);    
    image.setLayoutParams(rlParams);
    
    RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
            (LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    tParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    TextView text=new TextView(this); 
    text.setText("GOLDEN Gate"); 
    text.setTextColor(Color.WHITE);                            
    text.setTypeface(Typeface.DEFAULT_BOLD);
    text.setLayoutParams(tParams);
    
    rLayout.addView(image);
    rLayout.addView(text);
    setContentView(rLayout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to implement SeekBarPreference class using http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html tutorial with RelativeLayout. First problem
I am trying to implement Fragments in my Project using the https://github.com/JakeWharton/Android-ViewPagerIndicator plugin. My
I am trying to implement a android app. I have problems with TextView in
I'm trying to implement async on Android but it keeps crashing my app, the
I am trying to implement Camera application in android,and i got some code from
I am trying to work with Accelerometer Sensor. So i tried this example: http://blog.androgames.net/85/android-accelerometer-tutorial/
I am having some difficulty with an Android layout problem. I am trying to
hi, I'm trying to implement something similar to the image attached. I have two
I'm trying to implement a custom ProgressBarPreference, adding at the bottom of a default
I'm trying to implement a subclass of TextView that prints the text vertically rotated,

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.