Basically, what I want to do is:
1.- I have two fragments "outside" the activity.
2.- Now there could be two possibilities, fragment 1 or fragment must be shown with a slide up animation.
3.- Fragment 1 is always above fragment 2 when both are on screen.
4.- Any of the fragments can hide, placing correctly the showing one at the botton of the screen.
I am a little bit lost with layout design. I have tried
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="-20dp"
android:visibility="gone" />
<FrameLayout
android:id="#+id/fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="-20dp"
android:visibility="gone" />
</RelativeLayout>
And I even show both of them at the same time. Even using different fragmenttransactions for each fragment. Using, android:layout_above doesn't work.
What is the simplest way to develop this design?
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-100dp"
android:orientation="vertical">
<FrameLayout
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorAccent"
/>
<FrameLayout
android:id="#+id/fragment2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPrimary"
/>
</LinearLayout>
</RelativeLayout>
Animate the linearLayout. And as per your requirement change the visiblity of framelayout(gone/visible)
Maybe using two FrameLayouts for FragmentA would help for the two scenarios.
When it is the only one visible you can use
android:layout_alignParentBottom="true"
When it is on top of FrameLayout holding FragmentB, you can use
android:layout_above="#+id/fragment2"
Then play with the "visibilities" of these based on your scenarios.
Related
My question is related to this one:
Multiple Fragments in One Activity
I'm displaying three fragments in an activity on a tablet: two only contain text(Ingredients and Steps) and one an Exoplayer and text. All the fragments are enclosed in respective Frame Layouts. I'm using the Constraint Layout as the parent layout. The ExoPlayer isn't uniformly displayed in both portrait and landscape modes due to the length of the text in the Ingredients fragment. It is supposed to always be to the right of that Fragment and above the Steps Fragment. The two other Fragments are displayed properly on the left of the screen.
I thought about using a Linear layout and setting layout weights but then read in several posts that it's not recommended. What is the best way to display the ExoPlayer fragment in this type of layout? Thank you in advance.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tablet_detail_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="annin.my.android.bakingapp.ui.IngredientStepsActivity">
<!--
This layout is a two-pane layout for the master/detail flow.
-->
<FrameLayout
android:id="#+id/ingredients_fragment_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#+id/steps_fragment_container"
app:layout_constraintVertical_weight="0.4"
>
</FrameLayout>
<FrameLayout
android:id="#+id/video_fragment_container"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_marginStart="5dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="60dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="#+id/ingredients_fragment_container"
app:layout_constraintVertical_weight="0.4" >
</FrameLayout>
<FrameLayout
android:id="#+id/steps_fragment_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="40dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ingredients_fragment_container"
app:layout_constraintVertical_weight="0.4"
>
</FrameLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
Its pretty straightforward, just make 2 fragment and then assign them the respective fragment files like so:
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/my_fragment"
android:name="annin.my.android.bakingapp.ui.Fragment1" />
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/my_fragment_2"
android:name="annin.my.android.bakingapp.ui.Fragment2" />
I have a layout wich contains next views:
<android.support.v7.widget.RecyclerView
android:id="#+id/rvChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stickersContainer"
android:layout_alignParentTop="true" />
<ImageButton
android:id="#+id/ibChatSmile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6"
android:background="?attr/selectableItemBackgroundBorderless"
android:paddingBottom="8dp"
app:srcCompat="#drawable/smile" />
<LinearLayout
android:id="#+id/stickersContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="visible">
<android.support.design.widget.TabLayout
android:id="#+id/tbStickers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/stickersPager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/tbStickers"
android:visibility="gone" />
</LinearLayout>
stickersContainer - is layout which I want to show/hide. Recyclerview contains chat messages and ImageButton shows/hides
stickersContainer. As you see there are tabLayout and ViewPager in stickersContainer.
To ViewPager I load this fragment:
<FrameLayout 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"
tools:context="com.oopslab.outarguemechat.Fragments.Stickers.StickersContainerFragment">
<GridView
android:id="#+id/gvStickersContainer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:numColumns="3" />
for hiding/showing layout I use setVisibility() function;
and it seems all works well until I called notifyDataSetChanged() for recyclerview.
when I press a hide button it hides layout but button and recyclerview stayed at their places.
I'm really confused with this situation. I tried to put layout to the fragent and add/remove it but nothing helps
Also I tried adapter.notifyItemInserted() instead of notifyDataSetChanged() but had the same result
As you might guess, I'm trying to create something like sticker layout(like in viber/telegram/skype, etc).
May be there is another way to make it.
Thanks in advance!
My app uses one activity with a ViewPager to swap fragments for the app pages. Every other fragment works, but for some reason, one of them, my settings fragment, doesn't. The following image illustrates this. The red area is the unwanted margin. The blue area is a toolbar that is defined in the main activity layout - it is always there. The green area is the main ViewPager, also defined in the main activity layout:
This is what the MainActivity layout looks like:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Tab Bar -->
<com.rentalapp.rentmi.views.SlidingTabLayout
android:id="#+id/main_content_pager_tab_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="#color/primary" />
<!-- Content Pager -->
<android.support.v4.view.ViewPager
android:id="#+id/main_content_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/main_content_pager_tab_bar" />
</RelativeLayout>
</RelativeLayout>
And this is what the Settings fragment looks like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Settings"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="10dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log Out"
android:id="#+id/logout"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:paddingTop="10dp" />
</RelativeLayout>
How do I fix this unwanted margin? If I remove android:fitsSystemWindows="true" from the main layout, then every other page gets the notification bar drawn on top of the tab bar, which I do not want.
Not sure how, but I was able to fix it by removing the one android:fitsSystemWindows="true" that I had. Removing that in the past broke everything. Now it fixed it.
Hi i am new for android in my app i am adding Frame-layout inside LinearLayout but Frame-Layout and it's inside fields are not adding
my code is below please help me some one
main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent'"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight ="1"
android:layout_height="wrap_content"
android:background="#android:color/holo_red_dark"
android:text="something" />
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#android:color/holo_red_light"/>
</FrameLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frame" />
</LinearLayout>
I think you misunderstand the purpose of FrameLayout.
http://developer.android.com/reference/android/widget/FrameLayout.html
FrameLayout is designed to block out an area on the screen to display
a single item. Generally, FrameLayout should be used to hold a single
child view, because it can be difficult to organize child views in a
way that's scalable to different screen sizes without the children
overlapping each other.
You are trying to put two items inside of it. I would suggest removing the FrameLayout. You have no need of it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button" />
</FrameLayout>
</LinearLayout>
This works for displaying a single button, but there's no point in having it there.
I want to diplay this layout: Two fragments, the first one turned by 90 degrees counter-clockwise (well the layout of it) stuck to the left side of the screen and the second one filling the remaining space on the right side of it.
This is what I want to achieve:
I use this layout to display them floating the one over the other:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:orientation="vertical"
android:padding="0dp"
tools:context=".StartActivity" >
<fragment
android:id="#+id/first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="#dddddd"
android:padding="10dp" />
<fragment
android:id="#+id/second"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#333333"
android:padding="10dp" />
</LinearLayout>
EDIT:
The problem is that I don't manage to rotate the fragment and still ensure that the fragment's layout is anlingnt correctly while supporting API level 11+