SlidingPaneLayout does not cover the left side panel - java

how to understand it? why the left panel is not hidden?
My xml file:
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:id="#+id/headlines"
android:layout_height="match_parent"
android:name="by.zubov.task.fragments.TitlesFragment"
android:layout_width="380dp"
/>
<FrameLayout android:id="#+id/details"
android:layout_width="500dp"
android:layout_weight="1"
android:layout_height="match_parent" />
result:
Image result
testing this is code on Htc One (display 540x960).

you need to close your SlidingPaneLayout so you should add this line at the end of your XML
</android.support.v4.widget.SlidingPaneLayout
also (this shouldn't be the case right now) but if you use layout_with with a set amount of dp in both containers, it is possible that on a bigger screen both layouts are shown next to each other which means you can't swipe/slide anymore. So i'd recommend using android:layout_width="match_parent"` on at least 1 of your containers (probably the details pane) to prevent that from happening on a tablet for example.

Related

How to add item blocks to a scrollview?

I'm creating a simple app for personal use and I'm stuck because I need to add/remove a text from my scrollview. In the screenshot below the blue square is my scrollview and the mail button (placeholder) needs to open a popup where I can put 2 values in 2 different boxes, a string and a double.
Main_Activity
I know how to do almost everything but I don't know how to add a text every time I click on the mail button and it should look like this when I click on it
this is how it should be when is done
The left button of a car block is the "delete from scrollview" button that removes it from the scrollview and preferences and the right button that does like the 2nd image but where I can edit it.
My questions are:
How can I add a "block" of items in a scroll view? Per block I mean: Edit and delete button and the text like in the example.
Suggestions on what to use for the popup that adds 2 input fields?
In my opinion, I suggest to use recyclerView instead because of performance issues.
link
But, if you need to do the way using ScrollView just follow this.
In your xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_dark"
android:fillViewport="true"
android:padding="16dp">
<LinearLayout
android:background="#android:color/holo_red_light"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
And add item into linear layout when handle click event.
val linear = view.findViewById<LinearLayout>(R.id.linearLayout)
val item =
LayoutInflater.from(requireContext()).inflate(R.layout.item_list_row, linear, false)
linear.addView(item)

Positioning icon half above layout

Recently, designers in my company liked creating half-above elements in layouts for Android apps. I've been struggling for a while trying to make these elements behave as good as possible, but I'm already tired of it. Is there any way of positioning views like on this image
with an assumption that if user touch row/card it became "checked" and this black dot icon became visible (second click makes it invisible of course).
You can do something like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/circle_view"
android:background="#android:color/holo_blue_bright">
<android.support.v7.widget.CardView
android:id="#+id/second_view"
android:layout_width="100dp"
android:layout_height="match_parent"/>
</FrameLayout
<View
android:id="#+id/circle_view"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="#android:color/holo_red_dark"
android:layout_marginEnd="-8dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
second_view is endOf circle_view so if circle_view is gone second_view will align to startOf parent.
circle_view should have marginEnd set to negative value of its width divided by two

Android Studio: Graphics are cut

I have the Views attached to each other in the following order:
Activity->RelativeLayout->RelativeLayout->Text
When I change the Y of one of the Text attached to the inner RelativeLayout, parts of it are cut.
Here's a screenshot:
http://s28.postimg.org/ypmvrjz25/image.png
I'm coding purely in Java, no XML.
What's going on?
It looks like one layout is overlapping on another because the menu bar is pushing it down. If you just want the text centered I would suggest setting that in the parameters like so.
android:gravity="center"
This places the text in the center if that is what you want.
<?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"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView12"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
As #Jonathan Whalen suggested you probably have some overlap, I suggest you to change your relative layouts background color to see wich one is overlapping the text. Also try to not use fixed height for the layouts but use wrap_content instead, as fixed dims are frequently the cause of layouts overlap.

Android placing multiple bitmaps in imageview

I have multiple ImageViews which are transparent and are meant to over lap one another. I am aligning then to one another but one problem presist. How can I set the order in which they are layered? Ive tried revising the code in both xml and how the images are set in the actual java code...
I have tried FrameLayout but maybe Im not using it right...here is my implementation:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".RadarActivity" >
<ImageView
android:id="#+id/imageview_topo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageview_counties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
No matter what I do...imageview_topo is always placed on top. Even in the code i have instantated topo first and retrieved its image first!
Thank you!
I referred a site here that says:
If multiple child views exist, then they are drawn, in order, one atop
the other. This means that the first view added to the frame layout
will display on the bottom of the stack, and the last view added will
display on top.
You can check this site too: http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/
May be i can help you more if you show the screenshot of your UI.

How to display an options menu like this when buttons are pressed?

I'm stuck figuring how to do the following requirement.
I need to make a simple screen with two buttons, like this:
That part of the screen is already done.
The hardest thing for me is to make the behavior of the two buttons
when they are pressed. In that case, they must show an option menu
below like this:
Button 1 Pressed:
Button 2 Pressed:
I didn't start to program the menu yet,but in case it helps, this is
the layout for the screen (without the buttons).
<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:orientation="vertical"
android:background="#color/grayBackgound"
tools:context=".MenuActivity" >
<include android:layout_width="match_parent" layout="#layout/header" />
<include android:layout_width="match_parent" layout="#layout/loggedin_subheader"/>
</LinearLayout>
The layout for the header:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/header"
android:contentDescription="#string/header"
/>
<ImageButton
android:id="#+id/btnClose"
android:src="#drawable/btn_close"
android:contentDescription="#+string/salir"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="260dp"
/>
</FrameLayout>
The layout for the sub-header is almost the same.
I just need help to make the options menu for every button.
Thanks in advance!
The menu that you want to implement is what is commonly called a QuickAction Dialog. There are several tutorials available for that.
To get you started, here is a few links:
http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
https://github.com/ruqqq/WorldHeritageSite (This is not a tutorial per se, but has the complete implementation for the QuickAction Dialog)
https://code.google.com/p/simple-quickactions/ (You will need to make a few modifications in this)
The first link is the most promising in your case. If you scroll down that page to the Gallery3D-like QuickActions section, you will see it kind of resembles what you want the end result in your app to be. Naturally, goes without saying, you will still need to make modifications to the source available on the site.
Hope this helps. ;-)

Categories