I guess it's ok to set background color in some average fragment with average layout, but here I've got PreferenceFragment, which layout (PreferenceScreen) doesn't support android:background field. What's a neat way to handle it?
Add following to PreferenceFragment class declaration
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
view.setBackgroundColor(getResources().getColor(android.R.color.background_dark));
}
return view;
}
Adding my answer since I had a similar issue with PreferenceFragmentCompat that wasn't quite resolved by just adding a color to the background, and this was a top result while googling the problem.
I had the same issue where using PreferenceFragmentCompat would work, but the settings background was transparent and you could still see views in the underlying activty - changing .add() to .replace() in the getSupportFragmentManger yielded the same overlay.
The solution of changing the background color worked. However, for my build the getColor() method was deprecated. I instead use the following code.
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getListView().setBackgroundColor(Color.WHITE);
}
This solved the transparency issue except for one button, which was still clickable. For the sake of brevity, the issue was I was trying to replace the layout that contained the activity views.
What ended up working was creating an empty layout at the highest order and using .replace() on that layout. The buttons are now covered and no longer clickable.
XML where button was still visible above preferences fragment.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--I was replacing this layout that had all the activity views-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<TextView
android:text="Z"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/earth_acc_z"
app:layout_constraintTop_toBottomOf="#+id/earth_acc_y"
app:layout_constraintStart_toStartOf="#+id/earth_acc_y"
app:layout_constraintEnd_toEndOf="#+id/earth_acc_y"
app:layout_constraintHorizontal_bias="1.0"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/toggleRecording"
app:layout_constraintStart_toStartOf="#+id/toggleRecording"
android:layout_marginStart="8dp"/>
</FrameLayout>
</android.support.constraint.ConstraintLayout>
XML of working example with new empty constraint.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--FrameLayout with two nested ConstraintLayouts-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<!--ConstraintLayout with acitivty views-->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="#+id/frameLayout">
<TextView
android:text="Z"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/earth_acc_z"
app:layout_constraintTop_toBottomOf="#+id/earth_acc_y"
app:layout_constraintStart_toStartOf="#+id/earth_acc_y"
app:layout_constraintEnd_toEndOf="#+id/earth_acc_y"
app:layout_constraintHorizontal_bias="1.0"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/toggleRecording"
app:layout_constraintStart_toStartOf="#+id/toggleRecording"
android:layout_marginStart="8dp"/>
</android.support.constraint.ConstraintLayout>
<!--Preference fragment should replace this empty layout-->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/preferenceFragment"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.constraint.ConstraintLayout>
</FrameLayout>
</android.support.constraint.ConstraintLayout>
Related
Edit: everything is fine with the code, Android Studio is not deploying changes to app version 4.1.3
Im trying to change the background color of view(Relative layout and rootView) at runtime
but its not working at all here is the code
rootview = findViewById(R.id.rootView)
rootview.setBackgroundColor(resources.getColor(R.color.backgroundColor2))
Layout code/file, I'm using relativeLayout as the main layout here which is overridden by another view completely
<?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:id="#+id/rootView"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/banner_container"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
<at.markushi.ui.CircleButton
android:id="#+id/button"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_launcher_foreground"
app:cb_color="#color/mainButtonColor1"
app:cb_pressedRingWidth="8dip" />
<at.markushi.ui.CircleButton
android:layout_width="64dp"
android:elevation="8dp"
android:layout_height="64dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
app:cb_color="#B71C1C"
app:cb_pressedRingWidth="8dip" />
</RelativeLayout>
If I set the background in XML it works fine
I think because you are using a Relative layout. So maybe, your relative layout is overridden or covered by another View (like view 2 is covered by view 1 and view 3 ). And when you change the background of view 2, this function worked but you don't see it because it is being covered by view 1 and view 3. You should try Liner Layout to replay.
I have a dialog fragment, in which I have a recycler view. I want to add a scrollbar to the recycler view. I added scrollbars="vertical" but it's not showing up. I think the issue has something to do with the themes.
Here is my xml:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="16dp"
tools:context="com.airxos.app.common.fragments.LayerSwitcherFragment">
<TextView
android:id="#+id/layer_list_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:fontFamily="sans-serif"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#color/black_87"
android:text="#string/layers"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/layer_list"
android:layout_marginTop="#dimen/margin_16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/layer_list_title"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="0dp"
android:maxHeight="#dimen/info_window_height"
android:layout_width="match_parent"
android:nestedScrollingEnabled="true"
android:scrollbars="vertical"
android:background="#color/white"
android:scrollbarThumbVertical="#drawable/scrollbar"
android:scrollbarSize="5dp"
android:padding="5dp"
android:scrollbarStyle="insideInset"/>
</android.support.constraint.ConstraintLayout>
I am restricting the height and width of the dialog fragment as shown below:
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
Objects.requireNonNull(inflater, "LayoutInflater");
if(getDialog().getWindow() != null) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().setCanceledOnTouchOutside(true);
}
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_layer_switcher, container, false);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
Objects.requireNonNull(view, "View");
super.onViewCreated(view, savedInstanceState);
layerList = view.findViewById(R.id.layer_list);
layerList.setAdapter(new LayerListAdapter(context, layers, layerSelectionListener));
layerList.setLayoutManager(new LinearLayoutManager(context));
}
I have already tried everything suggested in this SO question and it did not work.
Other than this I have also tried creating a drawable and adding it as scrollbarThumbVertical
I think it has something to do with the themes because even when I change the background color of constraint layout it is not showing up in the dialog.
EDIT:
I am showing the dialog as shown below:
LayerSwitcherFragment switcherFragment = LayerSwitcherFragment.newInstance(layers);
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
Fragment prev = getChildFragmentManager().findFragmentByTag("layer_dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
switcherFragment.show(ft, "layer_dialog");
EDIT: Issue is solved.
I am sorry for wasting everyone's time. The issue was a stupid mistake we made. My DialogFragment was in a Library. We build the arr file and was using it inside the app. The issue was that we forgot to remove the dialogfragment's XML files from the main app when we refactored it to the arr library. So even after we update the files in the library, the app was picking up the old file in the main app instead of the updated file because the name of the XML was the same.
Try:
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
Try This:
In XML:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" <!-- type of scrollbar -->
android:scrollbarThumbVertical="#android:color/darker_gray"
android:scrollbarSize="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
In your xml, Just set the android:scrollbars="vertical" it can work.
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
I know this can come kind of late. Try to use a NestedScrollView as the parent of the RecyclerView. Like this:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/layer_list_title"
app:layout_constraintEnd_toEndOf="parent"
android:scrollbars="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/layer_list"
android:layout_marginTop="#dimen/margin_16"
android:layout_height="wrap_content"
android:maxHeight="#dimen/info_window_height"
android:layout_width="match_parent"
android:nestedScrollingEnabled="true"
android:background="#color/white"
android:padding="5dp"/>
</androidx.core.widget.NestedScrollView>
I guess in DialogFragment you scrollbar is transparent
try this code
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/mTaskListRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarSize="5dp"
android:scrollbarThumbVertical="#drawable/shape_progress"
android:scrollbarTrackVertical="#drawable/shape_round_gray"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="#layout/cash_out_task_list_item_layout" />
my activity_main.xml has two framelayouts that acts as containers for two fragments .When i run each fragment individually ,they run good .when i try to initialize and display both fragments ,one of the fragments called recents fragment is taking the full screen view .
when i run this fragment individually ,it takes full screen view instead of running in its own container.
and when i try to initialize my second fragment after initializing recents fragment i get an errorNo view found for id 0x7f070044 (com.example.diary:id/allnotesfragment) for fragment BlankFragment{7eb6bf4 (bc0fee9d-4a46-4e2b-ab31-d060c0ec14ae) id=0x7f070044}
activity code where i initialize both the fragments are is given below
package com.example.diary;
public class MainActivity extends AppCompatActivity {
int j;
List<NotesEntry> entries;
RecyclerAdapter adapter;
NotesDatabase db;
int numofitems;
String notesdata = "new_notes";
String defaultnotes = "old_notes";
Context c = this;
GridLayoutManager gridLayoutManager;
RecentsFragment recentsFragment;
ActivityMainBinding binding;
String textfortest;
int id;
FragmentManager fragmentManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecentsFragment recentsFragment=new RecentsFragment();
BlankFragment blankFragment=new BlankFragment();
fragmentManager =getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.recentsfragment,recentsFragment).commit();
fragmentManager.beginTransaction().add(R.id.allnotesfragment,blankFragment).commit();
}
}
its layout xml is
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/recentsfragment"
android:layout_width="395dp"
android:layout_height="325dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.618"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view"></FrameLayout>
<view
android:id="#+id/view"
class="android.widget.Button"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="#android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="-51dp" />
<FrameLayout
android:id="#+id/allnotesfragment"
android:layout_width="395dp"
android:layout_height="327dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="#+id/view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></FrameLayout>
i tried to implement it on other layouts too ,but the result is same.
thanks for your time
Your layout is most likely incorrect. Try something like this.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:id="#+id/main_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/fragment_container1"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/some_view"/>
<view
android:id="#+id/some_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/fragment_container1"
app:layout_constraintBottom_toTopOf="#id/fragment_container2"/>
<FrameLayout
android:id="#+id/fragment_container2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/some_view"
app:layout_constraintBottom_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
After spending a lot of time on it, I found that the problem is not with the layout but with the fragment itself.
In the oncreateView method of a fragment, I used databinding to refer to view instead of findViewById() and I have implemented a wrong way of databinding.
so by implementing databinding in the following way, I solved my problem.
fragmentBlankBinding = FragmentBlankBinding.inflate(inflater,container,false);
fragmentBlankBinding.recyclerView.setAdapter(adapter);
fragmentBlankBinding.recyclerView.setLayoutManager(layoutManager);
view=fragmentBlankBinding.getRoot();
return view;
Note: you need not refer to any layouts using this method as the layout is automatically fetched from databinding layout file of your fragment.
Hope it helps someone
I want to put a ConstraintLayout programmaticly in another ConstraintLayout. But it does not show up, if I inflate it the way I did before with a RelativeLayout.
Here's the code inner file inner_area.xml:
<android.support.constraint.ConstraintLayout 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:id="#+id/innerArea"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/grade_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="#drawable/onegreen"
app:layout_constraintBottom_toTopOf="#+id/h1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/v1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_conversion_absoluteHeight="20dp"
tools:layout_conversion_absoluteWidth="30dp"
tools:layout_conversion_absoluteX="0dp"
tools:layout_conversion_absoluteY="0dp" />
<ImageView
android:id="#+id/grade_three"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="#drawable/threelila"
app:layout_constraintBottom_toTopOf="#+id/h2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/v1"
app:layout_constraintTop_toTopOf="#+id/h1"
app:layout_constraintVertical_bias="0.0"
tools:layout_conversion_absoluteHeight="20dp"
tools:layout_conversion_absoluteWidth="30dp"
tools:layout_conversion_absoluteX="0dp"
tools:layout_conversion_absoluteY="20dp" />
.....
</android.support.constraint.ConstraintLayout>
Outer LayoutFile parent.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:orientation="vertical"
android:id="#+id/parentView"
android:background="#color/primary">
</android.support.constraint.ConstraintLayout>
Javacode:
ViewGroup parentView = rootView.findViewById(R.id.parentView);
final ConstraintLayout innerArea = (ConstraintLayout) inflater.inflate(R.layout.inner_area, container, false);
parentView.addView(innerArea);
But when I change in the inner.xml the layout_width or layout_height of the innerArea to wrap_content or match_parent, nothing happens. But when I change to 2000dp the inner layout shows up.
What am I doing wrong or missing?
Thanks to Cheticamp for pointing me in the right direction. I was inflating the ConstraintLayout with the root layout and not with the Constraint Layout it is supposed to be in. So the correct Javacode is:
parentView = rootView.findViewById(R.id.parentView);
ViewGroup parentView = rootView.findViewById(R.id.parentView);
final ConstraintLayout innerArea = (ConstraintLayout)
inflater.inflate(R.layout.inner_area, parentView, false);
parentView.addView(innerArea);
I seem to be very late to the party but I tried lots of things to solve this problem but nothing worked.
I ended up just putting the inner constraint layout inside another layout (a relative layout in my case) which solved the problem for me.
I'd like to achieve such a layout, where user got 2 control panels. He is able to switch from first to second by pressing button and vice versa.
Already have tried to use LayoutInflater, however, without success :/
The main reason, why doing it with 2 different layouts is, that buttons will be almost on the same position, so i'd like to prevent all that mess in one layout and create 2 separate control panel layouts.
Here are my layouts:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/control_panel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5">
<!-- Here comes including layouts-->
</RelativeLayout>
</LinearLayout>
control_panel_1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/control_panel1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector2"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btn_action1"
android:layout_marginRight="50dp"/>
<Button
android:id="#+id/btn_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector3"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btn_action1"
android:layout_marginLeft="50dp" />
</RelativeLayout>
control_panel_2.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/control_panel1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector4"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_action4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector5"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btn_action3"
android:layout_marginTop="20dp"
android:layout_marginRight="60dp"/>
</RelativeLayout>
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_root);
RelativeLayout controlPanelLayout = (RelativeLayout) findViewById(R.id.control_panel_layout);
//Inflate first control panel on activity start
LayoutInflater layoutInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View controlPanel1 = layoutInflater.inflate(R.layout.control_panel_1.xml);
controlPanelLayout.addView(controlPanel1)
}
EDIT:
As shown in the image, let's say activity starts with Screen1 and once user press Btn1, Screen2 appears...as you can see, only control panel has been switched.
however, it won't inflate that layout at start of application...
Thanks in advance for any suggestions, hints...
Inflate your control panel in onCreateView() and when handling button click (to change panel). The code should be somewhat like this:
private void inflateYourPanel(int panelLayoutID, ViewGroup placeholder) {
placeholder.removeAllViews();
View view = LayoutInflater.from(mActivity).inflate(panelLayoutID, placeholder, false);
//find your views and set values and listeners
placeholder.addView(view);
}
Edit: placeholder may be any layout (control_panel_layout) inflated when starting activity etc
Still may be you'd better look at Fragments - it may fit your purpose better and provide more scalability