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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:11:30+00:00 2026-06-05T06:11:30+00:00

I want to use a 9-patch drawable to use as the background of layout

  • 0

I want to use a 9-patch drawable to use as the background of layout which I set to be clickable

the drawable I use is actually a selector xml which I wrote like that:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/action_item_pressed" />
    <item android:drawable="@drawable/action_item" />
</selector>

and my layout is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:clickable="true"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:padding="8dp"
    android:background="@drawable/action_item_btn">

<ImageView
    android:id="@+id/icon" 
    android:layout_width="30dp" 
    android:layout_height="30dp"
    android:src="@drawable/sword_item"
    android:scaleType="centerInside"/>

<ProgressBar 
    android:id="@+id/progress"
    android:layout_width="35dp"
    android:layout_height="5dp"
    android:layout_marginTop="2dp"
    style="@android:style/Widget.ProgressBar.Horizontal"/>
</LinearLayout>

the problem is that the action_item drawable is not showing and action_item_pressed drawable is showing when pressing on the view.

any thoughts?

does the way I inflate this view, can cause this?

BTW: in the eclipse graphical layout, it is showing and if I add the view when the application is running, it works.

here’s the way I inflate this view (it calls from the onCreate method):

int achievementsNumber = AchievementsManager.ACTIVE_ACHIEVEMENTS_COUNT;
    m_achievementsLayout = new LinearLayout(m_context.getApplicationContext());
    m_achievementsLayout.setOrientation(LinearLayout.VERTICAL);
    m_achievementsLayout.setGravity(Gravity.CENTER);

    LayoutInflater inflater = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for(int i=0; i < achievementsNumber; i++){
        inflater.inflate(R.layout.achievement_item, m_achievementsLayout, true);
    }

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    addView(m_achievementsLayout, params);
  • 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-05T06:11:33+00:00Added an answer on June 5, 2026 at 6:11 am

    well it seems that inflating this view and adding it to the layout on the onCreate of the activity is a problem and caused this issue.

    I moved the inflating and added the view after the onResume and it works.

    I guess the reason is that the ViewGroup I’m adding the inflated view to, doesn’t have a size yet.

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

Sidebar

Related Questions

I want to read the html file.And for that I use System.IO.File.ReadAllText(path) .It can
I'm building a collection of RESTful resources that work like the following: (I'll use
Lets use a real world example. I want to monkey patch WillPaginate::LinkRenderer.to_html method. So
I have code that searches a folder that contains SQL patch files. I want
I have a patch which I'd like to split into two patches. I need
If I want to use the image as button background, how can I do
I did some search online. I know that you can use format-patch after commit,
I like to use git add --patch (and more recently, git add -i) to
I want to know that on button click how the background color changed here
I have 5 buttons having a 9 patch image set as its background. but

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.