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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:01+00:00 2026-06-05T07:09:01+00:00

I have a custom RelativeLayout in remote_image_view.xml : <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=wrap_content

  • 0

I have a custom RelativeLayout in remote_image_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
    <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/placeholder"
        />
</RelativeLayout>

Okay, now I want to include it in main.xml:

<?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">
    <Button android:text="Start Download" android:id="@+id/button1"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:onClick="onClick" />
    <Button android:text="View Downloads" android:id="@+id/button2"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:onClick="showDownload" />
    <ScrollView
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        >
        <LinearLayout
                android:id="@+id/lay"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="vertical"
                >
            <include layout="@layout/remote_image_view" android:id="@+id/imageView1" />
            <include layout="@layout/remote_image_view" android:id="@+id/imageView2"/>
            <include layout="@layout/remote_image_view" android:id="@+id/imageView3"/>
            <include layout="@layout/remote_image_view" android:id="@+id/imageView4"/>
            <include layout="@layout/remote_image_view" android:id="@+id/imageView5"/>
            <include layout="@layout/remote_image_view" android:id="@+id/imageView6"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

That’s good. So I created a class RemoteImage:

public class RemoteImageView extends RelativeLayout {

    public RemoteImageView(Context context) {
        super(context);
    }

    public void init(RelativeLayout.LayoutParams layoutParams) {
        LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.remote_image_view, this);
        setLayoutParams(layoutParams);
    }
}

And there a wild question appears.
I cannot write code as below:

RemoteImageView rm1 = (RemoteImageView)findViewById(R.id.imageView1);

Because I’ll get exception:

java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to com.dmact.remoteimage.RemoteImageView

So I should create an instance of RemoteImageView dynamically and then apply some LayoutParams to it. Is there a way not to do this? I want to make the layout in XML, not in code.

  • 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-05T07:09:03+00:00Added an answer on June 5, 2026 at 7:09 am

    If you need to subclass RelativeLayout using your RemoteImageView class you must also specify your class in the XML file

    ex

    <?xml version="1.0" encoding="utf-8"?>
    <com.yourpackagepath.RemoteImageView
                  xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content">
        <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/placeholder"
            />
    </com.yourpackagepath.RemoteImageView>
    
    • 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: <?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 created a custom listView with the row as follows: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have the following Custom Component: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=@dimen/bottom_actionbar_item_height android:orientation=horizontal android:gravity=center> <Button android:id=@+id/btnLogin
I have custom component that I can place in my layout file (XML) for
I have made a Custom Component in XML, consisting of a button with an
I have a custom listView. The main layout xml is something like this: <?xml
I´m having a problem with my Android Project. I have a screen filling custom
I have a custom dialog which described below. My Custom Dialog layout ( *my_dialog.xml*
it's my first question. I have built a custom component: a RelativeLayout with a
So I have a custom view set up in code (no XML layout defined

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.