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+
Related
I have a SearchView inside my Layout. In this layout, I have my ListView associate with the SearchView. When I edit my SearchView, I have the right result.
But I what my ListView to over the other element of my screen (such as a button). How do I do that ?
I see that it's what's done on iOS.
to sum up : I need the listView to be under my searchView AND in front of all other element (the list does not have to move down the reste of my layout)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="10dp"
android:id="#+id/layoutDepart">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background_input_no_padding"
android:weightSum="1"
android:id="#+id/layoutSearchViewDepart">
<android.support.v7.widget.SearchView
android:id="#+id/searchDepart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
app:iconifiedByDefault="false"
app:defaultQueryHint="Arrêt de départ"
app:queryHint="Arrêt de départ"
android:layout_weight="0.95"
android:padding="0dp"
android:layout_margin="0dp"
>
<SearchView
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
</android.support.v7.widget.SearchView>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#3a4770"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables"
android:tag="favArretItineraire"
android:id="#+id/favDepart"
android:layout_gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/mes_favoris"
android:textColor="#color/bleuFonce"
android:gravity="center"
android:paddingStart="10dp"
android:paddingEnd="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_star_yellow_24dp"
android:contentDescription="#string/mes_favoris"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/resSelectionLigneDepart"
android:visibility="visible"
android:background="#color/grayBg"
android:layout_below="#id/layoutSearchViewDepart"
>
<ListView
android:id="#+id/listSearchViewDepart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="0dp"
android:visibility="gone"
android:translationZ="15dp"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
When deciding what view to draw on top, android respects two things:
order in which views appear in the layout (next one is drawn over
previous one)
Z-coordinates - view with higher Z is drawn over view with lower Z
Note!
Old devices (below 21) do not use Z-order, only view order.
New devices (21 and above) use Z-order first and (for views with equal Z-coords) view order.
Your layout may look like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<FrameLayout
android:id="#+id/behindListViewWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- here goes everything that should be behind listview, for example button -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A button behind"
android:layout_gravity="center"
android:background="#f00"/>
</FrameLayout>
<ListView
android:id="#+id/listSearchViewDepart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#7000"
android:divider="#null"
android:dividerHeight="0dp"/>
<android.support.v7.widget.SearchView
android:id="#+id/searchDepart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
app:defaultQueryHint="Arrêt de départ"
app:iconifiedByDefault="false"
app:queryHint="Arrêt de départ"/>
</FrameLayout>
Why Button is wrapped in additional FrameLayout?
Because widgets can have default Z-coords. For button Z is equal 2 in normal state and 8 in pressed state (see https://material.io/design/environment/elevation.html). So in all cases the button will be drawn on top.
But that can be bypassed by wrapping button in other layout.
When desiding what to draw next, layout looks only for its direct children, not whole hierarchy. In this case all children have Z equal to 0, therefore behindListViewWrapper is the first to draw, then listview, then searchview.
If the button was not wrapped, it would be drawn on top (on modern devices, because of Z) or behind (on old devices, because of view ordering).
I would like to create an app that divides the screen into two squarish halves; in either orientation. The content within each half should rotate; but the two areas should remain fixed.
Could you tell me how to achieve this layout? I would like to place an embedded browser in one half, and a QR code scanner in the other.
I imagine this is a noobish question; I've done very little android development.
you can use layout weight sum and layout weight for this purpose.
use to following line of code:
<LinearLayout
android:id="#+id/head"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:weightSum="2"
android:baselineAligned="false"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_weight="1">
</LinearLayout>
set layout_weight to 1 in both LinearLayout will divide the screen equally.
<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"
tools:context=".Main"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_weight="1"
android:background="#9561A7"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--views of the first section-->
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:background="#006C91"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--views of the second section-->
/>
</LinearLayout>
good luck .
I am trying to use percentRelativeLayout to make my app 90% width of the screen size and 50% of the screen height.
My layout consists of two fragments: 1) the left side is 4 buttons and 2) the right side is a container that inserts a different fragment with each button click.
When I use percentRelativeLayout or percentFrameLayout to make the height 50% of the screen, and the width 90% of the screen I get the result below where it seems like I am getting my fragments as 50% height and 90% width INSIDE a box that is 50% of the height of the total screen and 90% of the width of the total screen. Does anyone know how I can fix this?
I have tried setting my layout_height and width to match_parent for both my layouts and the result is either the same, or the app takes up the whole screen. I also made sure to use a theme that takes up the whole screen, and not a Dialog theme. I have also tried using a parent RelativeLayout with a percentRelativeLayout nested inside with layout_widthPercent and layout_heightPercent applied to my fragments and I get the same result.
<android.support.percent.PercentFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout 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_gravity="center"
android:background="#drawable/rounded_edges"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_widthPercent="90%"
app:layout_heightPercent="50%"
>
<fragment
android:id="#+id/menuFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="5dp"
class="it.anddev.bradipao.janus.MenuFragment"
tools:layout="#layout/fr_menu">
</fragment>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.percent.PercentFrameLayout>
Here is what I want it to look like
Here is what it looks like now
It looks like your menu fragment's width takes about 30% of the total width of its dialog styled parent and the content takes about 70%. I would use a PercentRelativeLayout inside the PercentFrameLayout like the following
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.percent.PercentRelativeLayout
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:layout_gravity="center"
android:background="#drawable/rounded_edges"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
app:layout_heightPercent="50%"
app:layout_widthPercent="90%">
<fragment
android:id="#+id/menuFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_alignParentStart="true"
app:layout_widthPercent="30%"
class="it.anddev.bradipao.janus.MenuFragment"
tools:layout="#layout/fr_menu">
</fragment>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/menuFragment" />
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentFrameLayout>
As for the double white background appearing behind your Welcome fragment, I cannot really tell why it is happening without looking at its layout file. You may want to remove the background in the layout for all the fragments you replace in the container FrameLayout
Things which i have changed to show button is removed the menu fragment with four buttons to mimic the image you want as the result, you can replace this four buttons with the menu fragment
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#android:color/holo_blue_dark"
android:padding="4dp"
app:layout_heightPercent="50%"
app:layout_marginPercent="5%"
app:layout_widthPercent="90%">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:layout_weight="0.3"
android:background="#android:color/holo_purple"
android:contentDescription="this is where you can keep your buttons"
android:gravity="center"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="First"
android:textAllCaps="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="Second"
android:textAllCaps="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="Third"
android:textAllCaps="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="Forth"
android:textAllCaps="false" />
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_margin="4dp"
android:layout_weight="0.7"
android:background="#android:color/holo_green_dark"
android:contentDescription="this would be your frame container"></FrameLayout>
</LinearLayout>
</android.support.percent.PercentFrameLayout>
output
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.
I'm creating a calendar and will be having animations based on the current season.
i.e if it's winter, snowflakes will fall from the top of the screen.
Currently I have the calendar layout in place and when I draw my images at (0,0) I expect them to go to the top left of the screen... I'm adding my snowflake's to the main layout, but for some reason they go to the bottom of my gridView. I can only assume that one of my layouts is taking up space but I'm not sure..
Here is my calendar layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/calendar_main_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<Button android:text="Selected :"
android:id="#+id/main_header_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/calendar_top_header" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:id="#+id/calendar_left_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cal_left_arrow_off" />
<Button android:text=""
android:id="#+id/selected_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/calendar_centralheader"
/>
<ImageView
android:id="#+id/calendar_right_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cal_right_arrow_off" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/blue_bg_with_text" />
</LinearLayout>
<GridView
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="7" >
</GridView>
</LinearLayout>
here's a screenshot of what the calendar looks like in eclipse:
I'm adding my snowflake's to the main layout, but for some reason they go to the bottom of my gridView.
The root of your view hierarchy is a LinearLayout, which lays out all of its child views in order horizontally or vertically...none of them overlap. If you add another view to your root LinearLayout in Java code, it will get added and laid out after the last current child (which would be your GridView).
If you are adding your animated season images as additional views, you likely want to modify your application to have a FrameLayout at the root so that you can add views and have them simply overlay in the same space (they will pin to the top left unless you set a gravity value). This would not replace your existing LinearLayout, it would encompass them both, i.e.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/calendar_main_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Your entire existing layout now inside of here -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<!-- All the other existing stuff... -->
</LinearLayout>
</FrameLayout>
Now you can add your extra views to the FrameLayout and they should do what you expect.