I made a small android application that maintains a list of video files on the sd-card and plays it. I am using a listview with text and two images in each row. The problem I just noticed is quite usual. In horizontal mode, only those list items that fit into the screen area appears as normal while those items who require scrolling to get appeared, are either in wrong order or they are just repetition of the items in the top of the list. Moreover, by scrolling up and down, sometimes the order of items changes.. I am using two xml files. First for list view and second for the contents of the listview. here is the code for both xml files
<?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">
<ListView
android:id="#+id/list"
android:listSelector="#android:color/transparent"
android:divider="#drawable/bwgradient"
android:dividerHeight="1.5px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"
android:src="#drawable/cover"
android:scaleType="centerCrop"/>
<TextView
android:id="#+id/text"
android:state_focused="false"
android:listSelector="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left|center_vertical"
android:textSize="14dip"
android:layout_marginLeft="20dip"/>
<ImageView
android:id="#+id/play"
android:layout_width="30dip"
android:layout_height="30dip"
android:src="#drawable/play"
android:onClick="imageClick"
android:layout_gravity="center"
android:layout_marginRight="20dip"
android:scaleType="centerCrop"/>
</LinearLayout>
Any possible suggestion ??
when orientation changes from horizontal to portrait and vice verse,the activity will recreate itself(the Activity object destroyed and new Activity object will create).See docs http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges for more information
Related
Can anyone help me out how to delete a view from another activity and confirm the changes by calling notifydatasetchanged on a Viewpager.
This is View of My ViewPager Adapter which is getting called from a activity.
I want to delete a view which i'm able to achieve it from Viewpager adapter class but the problem is the delete and refresh buttons are not static with the view. I basically need the delete and refresh buttons to stick to page like footer in webpage. Right one if i swipe between views the buttons are also getting moved like how the images move.
I have seen several examples from past 2days but i could't find one which matches my criteria.
Can someone suggest me which approach to follow to achieve it.
Thanks a ton in Advance guys.
Here is my XML Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#090909"
android:orientation="vertical"
android:weightSum="1">
<com.example.vamshi.wheelbook.AddVehicle.ZoomableImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ViewPhoto"
android:scaleType="fitXY"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:src="#drawable/camera_black"
android:layout_gravity="top"
android:layout_marginTop="25dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ImageTitle"
android:text="Image1"
android:textColor="#ffffff"
android:gravity="center"
android:layout_alignParentTop="true"
android:textSize="18sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical"
>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#ffffff"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/ic_rubbish_bin"
android:id="#+id/Camera_Image_delete"
android:background="#null"
android:layout_gravity="center"
/>
</LinearLayout>
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#ffffff"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#ffffff"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_av_replay"
android:id="#+id/Retake_photo"
android:background="#null"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Activity A starting ViewpagerClass.
I want to delete a view from Activity A. How to do it?
I tired calling different methods from Activity A to delete it i was able to delete the View but notifydatasetchanged is not working that way i don't know y?
The solution is simple, extract the buttons from viewpager in your xml files, or put the buttons as actions in your actionbar/toolbar.
EDIT: by "extract" I mean, use viewpager only to swipe between views that contain your images or whatever you do with them, while the buttons remain stationary outside of the viewpager and "docked" to the bottom of the page.
I got a list from the web (link is here )
where it uses two xml layouts to create a list, the first xml is just the background where the second xml is going to be displayed as buttons in a list.
what I am trying to do is have that same list but add a tittle or a picture title at the top, i've been playing around with the list but i cant get it to work, the only way i can think to make this happen is somehow moving the position in which the second xml is displayed and have the top part to add whatever i like.
Thank you for the help and ideas to make this work!
[EDIT] code snippet...
First XML layout
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="schemas.android.com/apk/res/android";
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_weight="1"
android:scrollbars="none"
android:divider="#000000"
android:scrollingCache="true" android:layout_height="wrap_content"/>
Second XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#AA010101"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView android:id="#+id/list"
android:layout_width="1px"
android:layout_height="1px"
android:layout_weight="1">
</ListView>
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_height="fill_parent">
<ImageView android:id="#+id/img"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:scaleType="fitXY" />
<TextView android:layout_width="wrap_content"
android:id="#+id/title"
android:layout_height="wrap_content"
android:paddingTop="18dp"
android:layout_toRightOf="#+id/img"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_marginRight="50dp"
android:paddingLeft="10dp"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
You have to edit the XML file containing the <ListView>, by adding whatever you want before (most probably a TextView with a Compound Drawable). So that what you called the "background" looks more like this:
Main layout should host a <TextView> (+eventuall a Compound Image) + a <ListView>.
Secondary layout should host the content of each of your list item. If you have a <ListView> in each XML layout, it means you will have a list of lists... I don't know much about your list and app, and do not know what information you would like to display in each list item (e.g. ContactName, CalendarDate, Cities... whatever). But there are very few chances that you need a ListView in both of them.
mainListLayout.xml
<?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”>
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="text to replace image"
android:drawableLeft="#drawable/reference"
android:text="Title of the list"/>
<ListView
android:id=”#android:id/list”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content” />
</LinearLayout>
The Drawable can obviously be on the Right, Top or Bottom, and not only on the Left. You might also like to have a look at android:drawablePadding="#dimen/xxx to add some extra space between text/title and the image. Drawable has to be one of your ic_* png files from res/drawable (eventually -hdpi, -mdpi and so on)
itemLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:contentDescription="#string/ItemIcon"
android:layout_width="000"
android:layout_height="000"
android:src="#drawable/ic_icone"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<TextView
android:id="#+id/ItemDescription"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#000000"
android:text="ItemDescription" />
</RelativeLayout>
I am trying to built a ListView which has a line per player.
Each line should be very small but instead it is filling the whole screen with 2 massive lines.
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer android:id="#+id/slidingDrawer" android:handle="#+id/drawerHandle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:content="#+id/contentLayout" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:visibility="visible"
android:background="#000000">
<ImageView android:id="#+id/drawerHandle"
android:src="#drawable/blue_arrow_up_flat"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ImageView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/contentLayout" android:gravity="center"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView
android:id="#+id/lvwScores"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:divider="#FFFFFF" android:dividerHeight="1dip"
android:layout_weight="1" android:layout_marginBottom="60dip"
android:footerDividersEnabled="true" android:headerDividersEnabled ="true"
android:background="#000000"/>
</LinearLayout>
</SlidingDrawer>
Row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:id="#+id/tvwPlayerName" android:gravity="left"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<TextView android:id="#+id/tvwPlayerScore" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginRight="12sp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Try changing android:layout_weight="1" of ListView to 3 or >3..Might work out..
I think the ListView is drawn correctly.
You can see the two lines, the only problem is that they are drawn in the center and therefore look like they span the whole screen.
So I assume if you remove
android:gravity="center"
from your LinearLayout it should work.
And as a sidenote:
I never worked with SlidingDrawer, but its documentation states that you should use match_parent ( or fill_parent ) for its width and height. I assume you do not want to let the SlidingDrawer span over the whole screen if there is almost no content. Maybe this class does not allow other behavior, I do not know. But maybe this is the real source for your problem and not the ListView itself.
Edit:
Disregard my sidenote, the SlidingDrawer is drawn ontop with the blank area being transparent, therefore there should be no problem with its look...
I've searched for an answer for this all over but the solutions offered did not solve my problem.
I have a layout where I display some views (a few buttons and a background). To this i've added a custom control i've made extending linear layout. This control is displayed above the layout quite nicely.
What I wish to do is add an additional ImageView which is larger than this control but it will be in front of it.
edited: Sorry, I hope this will clear things up.
I have one large layout (Relative) for my activity, I would like to stack on this layout two additional views\layout so the final version will be the picture attached:
This is my layout - which stacks the imageview right on the menubar, and not over the others. Trying to put the FrameLayout elsewhere still didn't give me the wanted result.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="450dip">
<com.myproject.controls.SearchControl
android:id="#+id/scSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ExpandableListView android:id="#+id/lstItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scSearch"
android:layout_marginLeft="26dip"
/>
</RelativeLayout>
<FrameLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.myproject.controls.MenubarMain
android:id="#+id/mbMenuBarMain"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
/>
<ImageView android:src="#drawable/myicon"
android:layout_width="200dip"
android:layout_height="200dip"
/>
</FrameLayout>
</LinearLayout>
Not sure it this will work or not cause I'm typing this up at work. But moral of the story here is get used to using RelativeLayout. You have much more control over your layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<com.myproject.controls.MenubarMain
android:id="#+id/mbMenuBarMain"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
</com.myproject.controls.MenubarMain>
<com.myproject.controls.SearchControl
android:id="#+id/scSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</com.myproject.controls.SearchControl>
<ExpandableListView android:id="#+id/lstItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scSearch"
android:layout_above="#id/mbMenuBarMain"
android:layout_paddingLeft="26dp"/>
<ImageView android:src="#drawable/myicon"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignBottom="#id/mbMenuBarMain"
android:layout_alignRight="#id/mbMenuBarMain"/>
</RelativeLayout>
I want a list view and below of that list view i want one image.when i use the below code the list view and image view are appeared only in Portrait mode but not landscape mode, Can any one give me the suggestions for displaying that list view and image view in Landscape also.
My xml code is
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout
android:id="#+id/FrameLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="#string/apikey"
android:layout_height="wrap_content"
/>
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:id="#+id/linerlayouttransparent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="top"
android:paddingBottom="100sp"
>
<com.fitzengineering.teslaworldnet.presentationlayer.TransparentPanel
android:id="#+id/transparent_panel"
android:layout_width="fill_parent"
android:paddingTop="5sp"
android:paddingLeft="5sp"
android:paddingRight="5sp" android:layout_height="wrap_content" android:paddingBottom="5sp">
<LinearLayout android:id="#+id/LinearLayout01" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:id="#+id/ListView01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
</ListView>
<TextView android:id="#+id/TextView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:height="5sp">
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true" android:focusable="true"
android:src="#drawable/back_normal_icon"
android:layout_gravity="center_horizontal"
android:id="#+id/backImageView"></ImageView>
</LinearLayout>
</com.fitzengineering.teslaworldnet.presentationlayer.TransparentPanel>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
under your res folder, you probably have a folder like "drawable" for your image assets. You can add folders called "drawable-port" and "drawable-land" for resource images that are different in portrait and landscape mode...just give them the same filename in their respective folders and reference that filename in the layout code. This same technique can be used on your layout folders to create entirely different layouts in portrait and landscape if simply having two versions of an image isn't sufficient.
Pplease show me the screen shot for the problem you are facing. because from your XMl layout i can see that in the linear layout you have added the listwith height as fill_parent and then you have added text view and then ImageView. So might be this can cause a problem but until and unless i see the screen with the data, which you are displaying, i cant give you the exact point where to make change.