Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---SOLVED---
- the problem was I was passing the Application context,
- instead of the activity context.
- --- Original question ---
- How to programmatically add ImageView to -ROOT- default layout?
- (Without creating a new one)
- Explanation : When starting a new project, you get the a default XML.
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!" />
- </RelativeLayout>
- To create a new ImageView I use
- ImageView imageView = new ImageView(context);
- imageView.setImageResource(R.drawable.somePicture);
- imageView.setLayoutParams(new RelativeLayout.LayoutParams(
- RelativeLayout.LayoutParams.WRAP_CONTENT,
- RelativeLayout.LayoutParams.WRAP_CONTENT));
- Now.. in order to apply it to the Layout, i.e.
- someLayout.addView(imageView);
- I need to create that layout, and set it as
- someActivity.setContentView(someLayout);
- Problem is - I DO NOT want to create a NEW layout.
- In the GUI editor, I can just drag the imageView to the default layout.
- So, how can I programmatically access that default layout, and than use the addView on it?
- P.S. -
- Tried naming the layout and accessing with R.id,
- Tried "getWindow().getDecorView().getRootView();"
- I really feel like I'm missing something very basic in my understanding, but, what ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement