Issue creating a ListView menu in Xamarin/Android - android

I'm having trouble creating a simple menu of links in Xamarin. The desired layout is an image header, the list of links, and a button at the bottom to close the menu. I'm using a ListView to display the links.
My layout displays as desired in the Visual Studio Designer, but when run on the emulator or an actual Android device, the ListView takes up the entire screen and the header and footer aren't visible. I've tried everything I can think of, including several different layouts, and always get the same result.
My XAML is below. Help?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/topLayout">
<Toolbar
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:minWidth="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar1">
<ImageView
android:src="#drawable/logo1"
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1.0dp"
android:layout_gravity="center" />
</Toolbar>
</LinearLayout>
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/android.r."
android:background="#ffffffff" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2">
<Toolbar
android:minHeight="?android:attr/actionBarSize"
android:background="#ffff8902"
android:minWidth="25px"
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="#+id/toolbar3"
android:layout_alignParentBottom="true"
android:layout_marginTop="0.0dp">
<Button
android:text="^"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/menuCloser"
android:layout_gravity="center"
android:layout_marginLeft="0.0dp"
android:layout_marginRight="0.0dp"
android:textSize="40dp"
android:background="?android:attr/selectableItemBackground"
android:ems="1"
android:onClick="OnCloseMenu"
android:shadowColor="#android:color/transparent"
android:textColor="#ffffffff" />
</Toolbar>
</LinearLayout>
</LinearLayout>

In your list if you have more items then you have to scroll to get to the bottom to see the footer. Visual studio designer will show you the sample list with less items so that you can see header and footer. If you want footer to be placed in a fixed i.e you don't want to scroll then use relative layout.

Just replace your listview tag by
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/android.r."
android:background="#ffffffff" />
1> Issue was in your android:layout_height="0dp" it should be 0dp if you are using weight.
2> My suggestion is to use RecyclerView of android as you will face many inconsistency in ListView
3> Your code need to be cleanup as i think you are new to android
So as suggestion i just removed some unused properties,
<?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:id="#+id/linearLayout1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/topLayout">
<Toolbar
android:background="?android:attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:id="#+id/toolbar1">
<ImageView
android:src="#drawable/ic_back"
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</Toolbar>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/android.r."
android:background="#ffffffff" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2">
<Toolbar
android:minHeight="?android:attr/actionBarSize"
android:background="#ffff8902"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar3"
>
<Button
android:text="^"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/menuCloser"
android:layout_gravity="center"
android:layout_marginLeft="0.0dp"
android:layout_marginRight="0.0dp"
android:textSize="40dp"
android:background="?android:attr/selectableItemBackground"
android:ems="1"
android:onClick="OnCloseMenu"
android:shadowColor="#android:color/transparent"
android:textColor="#ffffffff" />
</Toolbar>
</LinearLayout>
</LinearLayout>

Related

How to display two list view inside a scroll view

I have looked at multiple examples and I'm also aware this is not good practice, but is there anyone that could help me with this issue. My first list is displayed correctly, but my second is collapsed and has it's own scroll view. I would like to have a scroll view for the entire page rather than for the individual list views.
<?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"
tools:context=".EtsiActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="?android:attr/actionBarSize">>
<TextView
android:layout_height="20dp"
style="?android:attr/listSeparatorTextViewStyle"
android:text="ETSI ERROR COUNT"
android:id="#+id/StatusHeader"
android:textColor="#color/primary"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dp" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etsiStatus"
android:layout_below="#+id/StatusHeader"
android:gravity="center_horizontal">
</ListView>
<TextView
android:layout_height="20dp"
style="?android:attr/listSeparatorTextViewStyle"
android:text="TS MAP"
android:id="#+id/TSHeader"
android:textColor="#color/primary"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dp"
android:layout_below="#id/etsiStatus"/>
<ListView android:id="#+id/TSList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/TSHeader"
android:gravity="center_horizontal"
/>
</LinearLayout>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_navigation_menu"
android:background="?android:attr/windowBackground" />
</RelativeLayout>
I believe a NestedScrollView is what you want. Take a look at Android: ScrollView vs NestedScrollView

When soft keyboard in fragment is viewed the top relative layout is hidden?

Like below shown image my activity is viewing like second image .How to solve this.
I am facing the issue in when the soft keyboard is pressed the the top relative layout is hidden and recycler view is placed below the relative layout is fully viewed i the screen.How to solve this. I searched all over the stack overflow but the problem was not solved.
The xml code is attached below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:layout_marginTop="?android:attr/actionBarSize">
<com.onefitstop.utility.CustomTextViewBold
android:id="#+id/chat_activity_label"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/white_partial"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="#string/chat_activity"
android:textStyle="bold"
android:textAllCaps="true"
android:textColor="#color/text_voiletlight"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_chat_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/chat_activity_label"
android:scrollbars="vertical" />
</RelativeLayout>
<include layout="#layout/error_screen"></include>
</RelativeLayout>
The included layout error_screen.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"
android:visibility="gone"
android:background="#color/white"
android:id="#+id/layoutError">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp"
android:layout_gravity="center"
android:src="#drawable/ic_error_1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<com.onefitstop.utility.CustomTextView
android:id="#+id/txtErrorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/error_msg"
android:textColor="#color/text_voiletlight"
android:textSize="24sp"
android:textStyle="bold" />
<com.onefitstop.utility.CustomButton
android:id="#+id/btnRefresh"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="Refresh"
android:textColor="#color/text_grey"
android:background="#drawable/refresh_button"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try to set android:windowSoftInputMode="adjustResize" in your <activity> in the Manifest. See more info here.

Android Studio UI PNG image overlayering a map

Im attempting to add a camera symbol at the bottom of my application (Like Snapchat) overlayering a map, but cant seem to make it work. The layer and the imagebutton within places itself below the layer containing the map object. If i reduce the hight of the "map-layer" it works, but then there is, naturaly, a white void on either side of the camera symbol which is centered.
Any suggestions? Here is a picture and the layout file, i included the whole thing in case i made some mistakes early on that causes the issue. All help is much appreciated.
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="#165d38">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton2"
android:src="#drawable/mark"
android:background="#00000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Swoop"
android:id="#+id/textView2"
android:textSize="18dp"
android:gravity="center_horizontal|right" />
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton3"
android:src="#drawable/mr_ic_settings_light"
android:layout_weight="0"
android:backgroundTint="#00000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<fragment tools:context="net.net16.swooptest.demomaps.MapsActivity"
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="fill_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:baselineAligned="false"
android:background="#00000000">
//THIS IS THE CAMERA BUTTON
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton4"
android:src="#drawable/abc_btn_radio_to_on_mtrl_015"
android:background="#00000000"
android:clickable="true"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Try to use android:elevation property so button will be above map in relative layout

Android: Multiple ListViews in a RelativeLaout

I am working on an app that has screen having multiple ListViews and that ListViews will contain Images by categories as (1st-Day, 2nd-Day and 3rd-Day). I have manged 3 different custom Adapters for this purpose and getting all Images from same service in a single ArrayList, just setting the adapter according date.
My problem is I need this screen to work like I want. This screen should be scrollable but in my case the listview just have some specific place on the screen instead it should expand to the bottom as of many list Items and by scrolling the second listview should be shown. I tried many solutions but didn't get what I actually want. I have also tried headers but that too not working for me the same problem of place. Below is the image how my screen looks like. As you can see the first ListView is just on a little place even it has many items and it should be expanded as of many Items but it don't.
And here is my XML Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:id="#+id/linearlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/re3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="center"
android:text="1st-Day"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</ListView>
<RelativeLayout
android:id="#+id/re4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent" >
<TextView
android:id="#+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="center"
android:text="2nd-Day"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</ListView>
</LinearLayout>
</RelativeLayout>
I have same required and for this You should use liner layout instead of ListView inside scroll view.
See This
and this
was solved my problem.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/list1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/list2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/list3"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

How to position a ListView in Android?

I want to put a ListView at the top of my activity, and something else on the bottom without the ListView "swallowing" the widgets on the bottom? I tried this (with the "something else" being a RelativeLayout with a single button in it), but it doesn't work.
<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" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
I looked for some hints here, which is very useful, but doesn't say anything about ListViews. I can place widgets above a ListView without problem, but not below.
Use a RelativeLayout as the root layout then position the ListView with layout_above and the Button with layout_alignParentBottom:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
I'm sure this is already answered several times on SO...
Change your layout like this:
<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" >
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
</LinearLayout>

Categories

Resources