I am new in Xamarin.Androiddevelopment.
I am trying to useFragmentswithNavigationView` but i have a problem
when i clicking on item in navigationView i dont see any response (menu close automaticly & i dont see click effect)
Drawer Navigation Configuried in MainActivity
Main.axml
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_width="match_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_height="match_parent"
android:layout_width="200dp"
android:layout_gravity="right"
android:fitsSystemWindows="true"
app:menu="#menu/menu"
/>
</android.support.v4.widget.DrawerLayout>
<FrameLayout
android:id="#+id/sample_content_fragment"
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0px" />
i tried to investigate this issue and
i thinking that something with menu items (null)
I attached a image here
Related
I have a recyclerview inside of a viewholder item that is for displaying up to 5 images nicely along with some other text. it's working pretty good except that the images are mega tiny looking, I'm not sure where I'm going wrong.
the main viewholder item layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="14dp">
<TextView
android:id="#+id/feedItem_txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginTop="14dp"
android:textColor="#color/dark_gray"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/feedItem_rvImageGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<View
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="15dp"
android:background="#color/very_light_gray"/>
</LinearLayout>
</LinearLayout>
the image grid viewholder item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/feedItemImage_ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
the code I'm using to bind the grid to the recyclerview
_layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.Vertical);
_feedItemImageAdapter = new FeedItemImageAdapter(_imageUrlsVisible, _imageUrlsFull);
_rvImageGrid.SetAdapter(_feedItemImageAdapter);
_rvImageGrid.SetLayoutManager(_layoutManager);
not sure what else you'd like to see, let me know if I need to provide more code samples, I'm at a lost on what I'm doing wrong.
One possibility is that your image size itself is small.
I tried to reproduce this question by using pictures of different sizes,when the image grid viewholder item is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/feedItemImage_ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
The result is :
But we can adjust the parent properties of the ImageView to
android:layout_width="match_parent"
android:layout_height="match_parent"
So when we use the following code:
<?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">
<ImageView
android:id="#+id/feedItemImage_ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
Now,we will find the image will be adjusted to the proper size,but at the same time,the picture is distorted and blurry.
How can I place an item on the screen in a way that it doesn't move even if I scrolled ? I am using a LinearLayout.
If you're open to wrapping your LinearLayout with a RelativeLayout, this will work and is flexible in that you can make most any type of view (e.g., Button) fixed.
Layout File
<?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">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtScrollingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</ScrollView>
<Button
android:layout_width="600dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="This Button Is Fixed"/>
</RelativeLayout>
Screenshot
Solution:
Use a FloatingActionButton would work.
When you Create a new simple view Xamarin.Android project, there is FloatingActionButton sample in the activity_main.axml:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
And in the activity, you can customize the click event.
FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
fab.Click += FabOnClick;
Here is a gif:
:
I have a little problem, which I can't seem to fix. I created a ImageButton and a TextView. They are below each other, but I want them to center vertically and horizontally. I already got it horizontally, but whatever I do.... I can't get it centering vertically (So in the middle of the screen). Here is my code:
<?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"
android:background="#0e2a56"
android:weightSum="100">
<ImageButton
android:src="#drawable/add"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="25"
android:id="#+id/imageButton1"
android:gravity="center_vertical|center_horizontal" />
<TextView
android:text="Add project"
android:textColor="#FFFFFF"
android:textSize="35dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/textView1"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
What am I doing wrong?
when we use a LinearLayout layout:
when android:orientation="vertical", android:layout_gravity only works for horizontal orientation, but not for vertical orientation. Left, right, and center_horizontal were rendered.
when android:orientation="horizontal", android:layout_gravity only works for vertical orientation, but not for horizontal orientation. top, bottom, center_vertical were rendered.
so if you want to center the imagebutton and textview,you could wrap them in RelativeLayout like this:
<?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:background="#0e2a56"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
>
<ImageButton
android:src="#drawable/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton1"
/>
<TextView
android:text="Add project"
android:textColor="#FFFFFF"
android:textSize="35dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/textView1"
/>
</LinearLayout>
</RelativeLayout>
I am building an Android TV app with the following layout:
Both lists on the left and on the right are RecyclerViews with vertical LinearLayoutManagers, Header view is static. Navigation with D-PAD works fine within one list, but when switching from one list to another there are issues. Focus moves from, say list1's item 5 to list2' item 5. When list 2 is short has less than 5 items, it just loses focus.
I want the last focused item index saved and when the user navigates list1-list2-list1 the item with that index to gain focus again and also prevent the views from losing focus. Is there any good solution to this?
Required behaviour:
user navigates to the top of the list and presses "UP" - focus stays where it was, nothing happens.
user navigates to the bottom of the list and presses "DOWN" - focus stays where it was, nothing happens.
user navigates from list1 to list2 - the item, that previously had focus in list2, gains focus or item0 gains focus if none was focused previously.
main layout:
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
>
<ImageView
android:id="#+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="27dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:layout_marginTop="27dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/iv_poster"
android:layout_width="#dimen/episodes_list_item_height"
android:layout_height="#dimen/episodes_list_image_width"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tv_release_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
/>
<TextView
android:id="#+id/tv_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:drawableLeft="#drawable/ic_star_white_24dp"
android:drawablePadding="#dimen/view_padding_small"
/>
</FrameLayout>
<TextView
android:id="#+id/tv_description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_seasons_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="false"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_episodes_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:focusable="false"
/>
</LinearLayout>
</FrameLayout>
item layout, used for both lists:
<?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="#dimen/seasons_list_item_height"
android:orientation="horizontal"
android:focusable="true"
>
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tv_episodes_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:ems="10"
/>
</LinearLayout>
Digging through Google's Leanback library sources answered my payers.
If you face the same trouble, just wrap your RecyclerViews with this and don't forget to set
private boolean mPersistFocusVertical = false;
if you want the focus to be persisted when searching horizontally, like in my layout.
Modify your main layout as below.
For directional navigation we can add properties like nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp to focus relevant items as per our requirements.
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
>
<ImageView
android:id="#+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="27dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:layout_marginTop="27dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/iv_poster"
android:layout_width="#dimen/episodes_list_item_height"
android:layout_height="#dimen/episodes_list_image_width"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tv_release_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
/>
<TextView
android:id="#+id/tv_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:drawableLeft="#drawable/ic_star_white_24dp"
android:drawablePadding="#dimen/view_padding_small"
/>
</FrameLayout>
<TextView
android:id="#+id/tv_description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_seasons_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="false"
android:nextFocusDown="#+id/rv_episodes_list"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_episodes_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:focusable="false"
android:nextFocusUp="#+id/rv_seasons_list"
/>
</LinearLayout>
Hope this will solve your problem !!
I want to do multiple things with the design support library. For example showing/hiding a floating action button when scrolling.
To achieve this behaviour a placed a WebView in a NestedScrollView, which is placed in a CoordinatorLayout.
I did the rest exactly like described here: https://guides.codepath.com/android/Floating-Action-Buttons
The problem i have is that there are multiple issues when placing a WebView in a NestedScrollView: The scrolling inside html components doesn't work correctly and when i load a smaller webpage than the previous shown webpage, a blank area appears on the bottom of the WebView.
Should i even use a NestedScrollView? Does anyone know how to use a WebView correctly with the Android Support Library? Both the issues are gone when i remove the NestedScrollView
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#FFFFFF">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarHeight">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
style="#style/toolbarStyle"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarHeight" >
<RelativeLayout
android:id="#+id/focusHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_centerVertical="true"
>
<ImageButton
android:id="#+id/refreshBtn"
android:src="#drawable/refreshicon"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#null" />
<EditText
android:id="#+id/addressBar"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_toLeftOf="#id/refreshBtn"
android:singleLine="true"
android:imeOptions="actionGo"
android:layout_centerVertical="true"
android:drawableLeft="#drawable/searchicon"
android:drawablePadding="5dp"
style="#style/addressBarStyle"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="match_parent"
android:layout_height="3dp"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
android:layout_alignParentBottom="true"
android:progressDrawable="#drawable/progressbar"/>
</RelativeLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- circular progressbar
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
-->
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
app:backgroundTint="#color/darkGreen"
app:borderWidth="0dp"
app:layout_behavior="com.example.fastbrowser.ScrollAwareFABBehavior"
android:clickable="true" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<!-- Nav drawer -->
<fragment
android:id="#+id/navigation_drawer"
android:name="com.example.fastbrowser.NavigationDrawerFragment"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="#dimen/toolbarHeight"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>