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.
Related
I'm making a layout (XML file) in Android that has two child views (one on the right side of the screen and one on the left). I want the view on the right to take up a pre-determined space (in dp) and have the view on the left take up all the remaining space up to a limit, at which point it will stop expanding and the two layouts will just move further apart as the screen gets larger.
The odd thing is this would be very easy if I wanted the view on the right side to be the one that expands, and the view on the left to be the one that takes up a preset space. If you set each view to the width you want (in a horizontal linear layout) Android will automatically shrink the one on the left in the event that both views don't fit.
I would like to do this in one layout file; this layout is already designed for displays between sw512dp-land and sw765dp-land.
The code below would work if I could find a way to make Android shrink the layout on the left (when layouts both cannot fit at the size specified). But by default the system will shrink the layout on the right first.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/left"
android:layout_width="150dip"
android:layout_height="fill_parent"
android:background="#color/red" >
</RelativeLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/green" >
</LinearLayout>
This code (from #Lokesh) would work if I didn't need the layout on the left to stop expanding at a certain point.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/right"
android:background="#color/red" >
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/green" >
</LinearLayout>
It would also be nice to know if anyone thinks this isn't possible so I can resort to doing it pragmatically or changing my approach to the layout.
Thanks!
This works for me. I've set the right layout to 100dip, change as per your needs.
<?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:orientation="horizontal" >
<LinearLayout
android:id="#+id/left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/right"
android:background="#color/red" >
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/green" >
</LinearLayout>
</RelativeLayout>
EDIT 1: I used the background color just to distinctly show the layouts. Not necessary at all. :)
EDIT 2: If you want a way to expand the left layout upto only a limit then try this -
<?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:orientation="horizontal" >
<LinearLayout
android:id="#+id/left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/right">
<LinearLayout
android:id="#+id/inner"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#color/yellow">
<TextView
android:id="#+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This will expand only to a limit"
android:maxWidth="300dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#color/red" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/green" >
</LinearLayout>
</RelativeLayout>
Here you need to place your widgets in inner layout and this is what it looks like in different screens.
3.1in HVGA
5.2in QVGA
Colors used : red(#FFFF00), yellow(#FFFFFF00), green(#FF00FF00).
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'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 have made layout for custom dialog, it has inside two imageview. I want to show both Imageview when dialog appear. and i want to hide the main layout of my xml file I have used "#00000000" as background:color, but it is not working.
Is there any way to do the same?
Thanks.
Here is my layout. I have taken screen shot please have a look i want to hide the border which are showing in image.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:background="#00000000">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView android:id="#+id/img_closeimage" android:src="#drawable/product_zoom_close"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"></ImageView>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_marginLeft="25dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="-5dip" android:layout_marginBottom="20dip" android:layout_marginRight="20dip">
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
></ImageView>
</LinearLayout>
</LinearLayout>
image description here
Adinias comment is correct, your layout has quite some redundancy. You also say that you only want to show an imageview, but your layout contains two imageviews. If you only want to show one imageview, then your layout should look like this:
<?xml version="1.0" encoding="utf-8"?>
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
If you want to show two ImageViews, use this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:background="#00000000">
<ImageView android:id="#+id/img_closeimage" android:src="#drawable/product_zoom_close"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"/>
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
</LinearLayout>
Your current layout looks the way it does because you have specified the layout to take as much space as possible with android:layout_height="fill_parent" and android:layout_width="fill_parent". Try to use wrap_content as height and width instead.
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