While playing around with the Gallery I've got another question (this probably should be simpler).
I'm trying to show a view, lying in front of the Gallery, probably hiding it partially. Like a message dialog (Toast).
In order to do so, I'm using a FrameLayout with a Gallery in the back, and ImageView with a transparent src in the front. When a dialog should be shown, I'm setting the src to the needed drawable through "sendImage".
The problem is, as I assume, that the gallery/list items (that are added dynamically upon "onRequestListItem -> sendListItem") have more recent z-Order (as they have been added later), so the dialog is shown between the background of the Gallery and the transparent icons, representing the list items.
Maybe someone will have an idea, how to avoid this situation?
I am not aware of any way of adding views manually to the layout on the SmartWatch, or changing their zOrder through "bringToFront".
Here is the source code:
gallery.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Gallery
android:id="#+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/toast_dialog_message" />
</FrameLayout>
gallery_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20px"
android:src="#drawable/item_icon" />
</RelativeLayout>
GalleryControlExtension.java
sendImage(R.id.spritz_image, drawableResourceId);
P.S. In the emulator it works as expected: toast lies over the item_icon ...
Related
I am working on a project where I have an activity, which has two fragments loaded in.
I have this working except I want to put a touch bar in the middle between the two fragments, that will allow the user to drag the bar which would then resize the each fragment, i.e. make one fragment grow the other fragment shrink.
Below is the current layout:
<?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"
xmlns:tools="http://schemas.android.com/tools">
<fragment android:name="com.company.myapp.LoginFragment"
android:id="#+id/login_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<fragment android:name="com.company.myapp.ApiFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/api_fragment" />
</LinearLayout>
Is there a specific way to do this in Android via an API or will I need to add my own and use touch/drag listeners to resize appropriately.
I made a little app with a map for learning.
Over the map I added a textView with actual position upgrading..
After some problems I did it with a such layout:
<?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"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<TextView
android:id="#+id/txt_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="TextView"
android:textSize="30sp"
android:textAlignment="center"
android:textColor="#drawable/common_google_signin_btn_icon_light"/>
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/txt_location"
android:layout_centerHorizontal="true"
app:srcCompat="#drawable/ic_action_name" />
</RelativeLayout>
Now I would add an imageView for showing gps status (focused, enabled, disabled).
I added the imageView under the textView, but I don't see anything.
After some try I'm asking why.
ps:
If I put imageVIew in a LinearLayout (before the map) I see linearLaout (in black for es.) over the map, and I still can't see image but, eventually, only the background if setted.
It's not my goal to add a linear layout, but also in this way I can't see image.
I created image by -> new image asset -> launcher icon (legacy only) clip-art (android logo) -> mo effects.
than I added it by reference in the imageView.
Solved!
I don't know if it's usual,
but adding ImageView from design window, it code Imageview as I posted.
Searching around I found similar situations and I found that correct way to show image over MapFragment is make a change to default code of ImageVIew:
from:
app:srcCompat="#drawable/img_name" />
to
android:src="#drawable/img_name" />
I don't know if I do something wrong with inserting new ImageView,
but hope this could help people that do as me.
I am creating a calculator app in android.Just like a modern calculator you see in your android device. I have created a TextViewand below that, all my buttons are present.I also want to include the trignometric functions so when buttons layout is swipped, i want to show trignometric function and when it is swiped back it show numeric buttons.The TextView should remain constant at the top.Can you somebody please guide me how to do that?
Yes u can do it.
here is an example how to do it
Layout Example
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Static content -->
<LinearLayout
android:id="#+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#color/holo_blue_light"
android:orientation="vertical" />
<!-- ViewPager Indicator -->
<com.viewpagerindicator.LinePageIndicator
android:id="#+id/view_pager_indicator"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_above="#id/ll_bottom"
android:background="#color/holo_orange_light"
app:lineWidth="10dp"
app:selectedColor="#fff"
app:strokeWidth="10dp"
app:unselectedColor="#888888" />
<!-- ViewPager containing fragments with different views -->
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/view_pager_indicator"
android:layout_alignParentTop="true"
android:background="#color/holo_red_light" />
</RelativeLayout>
In the blue region you place your static content which doesn't change like the
The orange region is used by the
ViewPagerIndicator and finally the red region is the one of the ViewPager. this area is swipeable.
I have this piece of layout or Android which is problematic:
<?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:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/influencerMainPhotoImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<android.support.v7.widget.RecyclerView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/photos_list"
android:name="com.company.android.InfluencerFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:context="com.company.android.InfluencerFragment"
tools:listitem="#layout/fragment_photo"/>
</LinearLayout>
The problem is that the embedded RecyclerView is doing nested scrolling (ie. it scrolls within itself) - I don't want this.
I'd like to the entire screen to scroll as a single piece.
I tried to set "view.setNestedScrollingEnabled(false);" (on the LinearLayout view) but it says it works only for API 21 and above. My project is set to min API 15.
What can I do to make the entire screen scroll as a single piece?
You can replace View with ViewCompat(v4 compat lib):
https://developer.android.com/reference/android/support/v4/view/ViewCompat.html
where you have the setNestedScrollingEnabled(boolean); method.
I'm developing a chat application. Recently I changed the Chat, Activity (no lag) to Fragment (so many lag when resizing) because I wanted to build a flexible UI but now there is my problem : When the keyboard show up or disappear the UI resizing is very laggy.
I tried to changed adjustpan and other inside the manifest -> not working
When I remove the recyclerview from de chat -> it works, no lag when the keyboard show up.
So I guess the problem is here (I'm not sure),
I noticed this error RecyclerView: No adapter attached; skipping layout
I tried to fix it with other post on stackoverflow but no success. The error also appears when I scroll the recyclerview or when the keyboard appears.
When I have lot of messages inside my adapter it's very laggy when the view is resizing.
About the architecture
The MainActivity have one container.
the container can contain fragments : FamilyFragment, SettingFragment, RootChatFragment
RootChatFragment -> building flexible UI (Contact Fragment and ChatFragment) or just Contact Fragment if it's mobile view
Can someone help me ? (sorry for my bad english)
Here a screenshot when I close the keyboard.
UPDATED, FIXED
Using android:layout_weight="value" was the problem but I don't know why.
Old one
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:fillViewport="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.myapp.fragments.SpaceContact"
android:id="#+id/contact_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.myapp.fragments.SpaceChat"
android:id="#+id/chat_fragment"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
</RelativeLayout>
New one without lag
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:fillViewport="true">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.myapp.fragments.SpaceContact"
android:id="#+id/contact_fragment"
android:layout_width="350dp"
android:layout_height="match_parent" />
<fragment android:name="com.myapp.fragments.SpaceChat"
android:id="#+id/chat_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/contact_fragment"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</RelativeLayout>