Listview is gone - java

Hi I am using Ribbon Menu library to show a sliding menu in my app
https://github.com/darvds/RibbonMenu
and here is my layout.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" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/abs__textfield_search_default_holo_dark"
android:drawableRight="#drawable/abs__ic_search"
android:ems="10"
android:gravity="right|center_vertical"
android:textColorHint="#7F462C" >
<requestFocus />
</EditText>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<com.darvds.ribbonmenu.RibbonMenuView
android:id="#+id/ribbonMenuView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
my problem here is that my list view is gone i mean i just can see the Ribbon Menu and the edit text so any help?

your include layout hidding your listview
<com.darvds.ribbonmenu.RibbonMenuView
android:id="#+id/ribbonMenuView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
set wrap_content or set the size to the layout_height to some value like "100dp"

Related

how to get a portion of a view outside of its parent?

I tried to create an actionBar like this one, "this is a website template "
so I created a file action_bar.xml which I'll inflate, A RelativeLayout which has a height of wrap_content & a width of match_parent , it has the gear icon and all other details except that I can't get a part of the round picture outside of the RelativeLayout like the picture.
I tried using margins but it doesn't get out of the RelativeLayout, The RelativeLayout gets extended instead. so, More margin in the picture results in more height in RelativeLayout.
Any suggestions?
<?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="wrap_content">
<ImageButton android:src="#drawable/roundPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="30sp"
android:layout_marginLeft="30sp"
android:padding="0sp"/>
<ImageButton
android:id="#+id/gearIcon"
android:layout_alignParentRight="true"
android:background="#drawable/gearICON"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10sp"
/>
</RelativeLayout>
No Libraries please, I'm not making an app, I'm just trying to understand.
quick recap. I want a part of the first ImageButton outside of the RelativeLayout
Check if it is this what you are looking for
EDIT:
<?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"
android:background="#000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff">
<ImageButton
android:id="#+id/gearIcon"
android:layout_alignParentRight="true"
android:background="#android:drawable/ic_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10sp"
/>
</RelativeLayout>
<ImageButton
android:background="#android:drawable/ic_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="30sp"
android:layout_marginLeft="30sp"
android:padding="0sp"/>
</FrameLayout>
First, I ran into a problem that my data appears under the ImageView, not behind it
but I fixed it by adding my data which is a listview, after the relativeLayout in the frameLayout, Thanks P.Juni for the idea btw
The XML which runs totally fine is
<?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="wrap_content"
android:background="#android:color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000">
<ImageButton
android:id="#+id/gearIcon"
android:layout_alignParentRight="true"
android:background="#drawable/ic_launcher_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10sp"
/>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<ImageButton android:id="#+id/imageButton"
android:background="#drawable/ic_launcher_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="60sp"
android:layout_marginLeft="30sp"
android:padding="0sp"/>
</FrameLayout>

Is there a way to check overview button?

I am developing an app where there is a left Drawer on the Home screen. The drawer fits perfectly on most devices, but on some devices, the drawer is covered whether the screen has overview button(phone without physical button, using on screen button) or its swallowed under the bottom of the screen(mostly happen on Xiaomi, and yes, i've tried on 5 xiaomi phones).This also happening on the emulator from android studio. The Question is, can the app knows if there a overview button on the phone , so the app can be developed to put the layout on top(not covering) of it. Or is there another way, more simple and efficient?
Here is the layout code:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/drawer_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<!-- *********** NAVIGATION DRAWER *********** -->
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="#dimen/drawer_width"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#color/drawerColor"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingLeft="#dimen/drawer_user_padding_left"
android:paddingBottom="#dimen/drawer_user_padding_bottom"
android:paddingTop="#dimen/drawer_user_padding_top_newest"
android:orientation="vertical" >
<TextView
android:id="#+id/referal_ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/nav_fontsize"
android:textColor="#color/orange"
android:textStyle="bold"
android:text="\nReferal ID: " />
<TextView
android:id="#+id/profile_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/content_fontsize"
android:textColor="#color/orange"
android:textStyle="bold"
android:text="000" />
</LinearLayout>
<LinearLayout
android:id="#+id/userdata_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/theme"
android:paddingLeft="#dimen/drawer_user_padding_left"
android:paddingTop="#dimen/drawer_separator_margin_top"
android:paddingBottom="#dimen/drawer_user_padding_bottom"
android:orientation="vertical" >
<TextView
android:id="#+id/profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/content_fontsize"
android:textColor="#color/white"
android:textStyle="bold"
android:text="Name" />
<TextView
android:id="#+id/profile_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/content_fontsize"
android:textColor="#color/white"
android:text="email#email.com" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/icon_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:background="#android:color/transparent"
android:src="#drawable/magno_coin"/>
<TextView
android:id="#+id/profile_credit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="#dimen/content_fontsize"
android:textColor="#color/white"
android:textStyle="bold"
android:text="0"/>
</LinearLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/upper_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/drawer_upper_nav_margin"
android:isScrollContainer="false"
android:scrollbars="none" >
</ListView>
<View
android:id="#+id/upper_separator"
android:layout_width="fill_parent"
android:layout_height="#dimen/drawer_separator_height"
android:layout_marginTop="#dimen/drawer_separator_margin_top"
android:layout_marginBottom="#dimen/drawer_separator_margin_bottom"
android:background="#color/contentColor"/>
<ListView
android:id="#+id/middle_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:scrollbars="none">
</ListView>
<View
android:id="#+id/middle_separator"
android:layout_width="fill_parent"
android:layout_height="#dimen/drawer_separator_height"
android:layout_marginTop="#dimen/drawer_separator_margin_top"
android:layout_marginBottom="#dimen/drawer_separator_margin_bottom"
android:background="#color/contentColor"/>
<ListView
android:id="#+id/lower_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:scrollbars="none">
</ListView>
<View
android:id="#+id/lower_separator"
android:layout_width="fill_parent"
android:layout_height="#dimen/drawer_separator_height"
android:layout_marginTop="#dimen/drawer_separator_margin_top"
android:layout_marginBottom="#dimen/drawer_separator_margin_bottom"
android:background="#color/contentColor"/>
<ListView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:layout_marginBottom="#dimen/item_margin"
android:scrollbars="none">
</ListView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="#dimen/drawer_separator_height"
android:background="#color/theme"/>
<TextView
android:id="#+id/current_version"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom|right"
android:layout_alignParentBottom="true"
android:layout_marginTop="#dimen/item_space_margin"
android:layout_marginBottom="#dimen/item_space_margin"
android:layout_marginRight="#dimen/version_margin"
android:textSize="#dimen/smaller_fontsize"
android:textColor="#color/black"
android:text="ver 1.0.0"/>
</LinearLayout>
</LinearLayout></android.support.v4.widget.DrawerLayout>
On the picture i scrolled down until cant be scrolled anymore
Sorry, if I dont understand your question.
I dont see in your xml android.support.design.widget.NavigationView - its container for drawer content. You need to add implementation 'com.android.support:design:27.1.1' to your app dependencies to use NavigationView.
And if you want to do static header for your drawer, there is app:headerLayout="#layout/nav_header" property, where nav_header is your header layout.
For other items there are app:menu="#menu/drawer_view property, where drawer_view is your drawers menu. In this menu you can put as many items as you wish and they will be scrollable if needed. Also you can design it as you want and they are easy for handling in NavigationView.OnNavigationItemSelectedListener
See this Googles guide for more details. Hope it will help you.
This is a common problem. Place a listview (or more) inside a scrollview is not good. If you have a finite number of elements I suggest you to build your view programmatically (use addView).
However if you don't want to change your code read that: list view inside scrollview.
Basically you need to calculate the real height of the listview for every item (getMeasuredHeight) after notifyDataSetChanged. This should fix your problem.
To prevent overlapping by Bottom Soft NavigationBar add this to your styles.xml in a values-v21 dir (if dir not exist, create one and copy same styles.xml file from value):
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
Like this eg -
<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
.....
.....
</style>

Android - what kind of view/xml I've to study

Problem I want view-layout like the following photo, on top I want image view, in the middle a text view and bottom list of items. All this I want to be scrollable (black arrow in the picture). in this way, the user for first see image-text-and part of list items, if scroll down, see the list of item.
For the bottom I thought to use listView, but in this way I think I'll have 2 scrollable view (???) and then I want to make the list in 2 columns, and I don't know if it is possible with ListView
Question
I didn't write code, because I want to know what kind of view or somethings else I've to study.
I sketchy something like this, but the result is really horrible
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:srcCompat="#drawable/nope"
android:id="#+id/imageView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<View
android:id="#+id/centerShim5"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:visibility="invisible" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textView2"
android:textColor="#color/ame_default_cluster_circle_color_medium"
android:textSize="26dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</ScrollView>
I can't use listview in Scrollview, and inspired by the matryoshka I found the solution.
I define xml1 file in which I have only ScrollView and LinearLayout inside
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linear">
</LinearLayout>
</ScrollView>
after, for each kind of items that I want to add inside, I define another xml2 and after I add element:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/ame_default_cluster_text_color">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:textSize="32sp"
android:textColor="#color/ame_default_cluster_circle_shadow_color"
android:id="#+id/text1"
android:textAlignment="center" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/nope"
android:id="#+id/photo" />
<TextView
android:text=" "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:id="#+id/descrtiption"
android:textColor="#color/ame_default_cluster_circle_shadow_color"
android:layout_margin="10sp" />
</LinearLayout>
with code:
layoutInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view=layoutInflater.inflate(R.layout.xml1,container,false);
LinearLayout linearLayout=(LinearLayout)item_view.findViewById(R.id.linear);
LayoutInflater inflater= LayoutInflater.from(ctx);
View view1 = inflater.inflate(R.layout.xml2, linearLayout, false);
TextView text1=(TextView)view1.findViewById(R.id.text1);
text1.setText();
ImageView imageview=(ImageView)view1.findViewById(R.id.photo);
and obviously I can define XML for element to add like listview and add it with normal foreach ,Hope this will help someone.

Button in Android XML Layout

I'm working with a package some fellow members found for me that allows a slider to start at the top and slide to the bottom. I need to add content behind the slider, but I'm unsure of where to put it in the XML. Maybe I have to add a linear layout, but I'm not sure. I just need to add one button that sits in the very center of the screen. I think it needs to be put in the following code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:ns="http://schemas.android.com/apk/res/it.sephiroth.demo.slider">
<Button
android:id="#+id/button_open"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:layout_centerInParent="true"
android:visibility="gone" />
<it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/it.sephiroth.demo.slider"
android:id="#+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
ns:content="#+id/content"
ns:direction="topToBottom"
ns:handle="#+id/handle" >
<include
android:id="#id/content"
layout="#layout/pen_content" />
<ImageView
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="40px"
android:src="#drawable/sliding_drawer_handle_bottom" />
</it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer>
</RelativeLayout>
I'd also like for the button to be behind the drawer.
Any help would be great!
Try This:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:ns="http://schemas.android.com/apk/res/it.sephiroth.demo.slider">
<LinerLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button_open"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:layout_centerInParent="true"
android:visibility="gone" />
</LinerLayout

android: image in icon not showing

I'm trying to place a banner at the top of a listview, one that stays there when the list scrolls down. The layout I currently have actually show what I want in the preview but when I run it in the emulator the only thing that appears is the list.
The XML is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="#drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/EdUniCrest" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"></ImageView>
<TextView android:layout_height="wrap_content" android:id="#+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_toRightOf="#+id/EdUniCrest"
android:layout_alignParentRight="true" android:layout_alignBottom="#+id/EdUniCrest"
android:background="#25476C"></TextView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#color/listcolor" android:orientation="vertical" android:layout_marginTop="50dp">
<ListView android:id="#android:id/list" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
<TextView android:id="#android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="#string/no_lunchs" />
</LinearLayout>
Anyway, I can't see why it isn't working. Does anyone have any idea what it might be?
Thanks.
The RelativeLayout here just makes it confusing. You can achieve this simply with a couple of LinearLayouts. Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. The list will then fill all available space. The List will scroll independently of the rest of the page.
Something like below should work:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal" android:id="#+id/bannerBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:src="#drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/EdUniCrest"/>
<TextView android:layout_height="wrap_content" android:id="#+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:background="#25476C"/>
</LinearLayout>
<ListView android:id="#android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="#android:id/empty" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="#string/no_lunchs" />
</LinearLayout>
What if you wrapped your RelativeLayout in a ScrollView, and since a ScrollView can only have one child, put the banner above it?

Categories