not whole list item is clickable in the ListView - android

Yes I read this question. No it didn't help.
The problem is that only the highlighted area of my ListView cell is clickable. It is the area that is filled with text. Take a look on the picture:
So when you click on the circled area - it wouldn't respond.
Any ideas on how to make it work properly???
Edit: my list layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="#+id/shoulderLogo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp">
</ImageView>
<TextView
android:id="#+id/shoulderLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>

I'm pretty sure this is because your list layout LinearLayout has a layout_width of wrap_content. This will cause your row to only be as wide as the views contained within. If you set it instead to fill_parent or match_parent it will extend to fill the width of your list.

Try changing to this
<?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"
android:padding="5dp">
<ImageView
android:id="#+id/shoulderLogo"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp">
</ImageView>
<TextView
android:id="#+id/shoulderLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>

Related

First view in RelativeLayout expand to fill remaining space

I am working on a layout with a cardview, a checkbox and a button with the initial structure as shown in the first image:
In this case the listview is not shown until the user clicks an image inside the cardview, so when this happens the dessired structure is like
the second image
However as the listview is actually inside a fragment I can't achieve the dessired layout because wrap_content and match_parent for the cardview gives me the next result
And as you can see the cardview overlaps the button and the checkbox goes beyond the screen
Right now this is my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#android:color/white">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/card"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_alignParentTop="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
>
<ImageButton
android:layout_width="#dimen/event_invitation_expand_icon"
android:layout_height="#dimen/event_invitation_expand_icon"
android:id="#+id/shrink"
android:src="#drawable/ic_shrink"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/shrink"
android:layout_marginTop="5dp"
android:id="#+id/list">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="ListFragment"
tools:layout="#layout/fragment_list"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:layout_marginTop="20dp"
android:layout_below="#+id/card"/>
<Space
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button"
android:layout_below="#+id/checkBox"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_alignParentBottom="true"
style="#android:style/Widget.DeviceDefault.Button.Borderless"
/>
I hope you can help me to set the max height of the card view to stop growing when the space is filled.
I have also tried to set the checkbox always at top of the bottom and the cardview to fill the remaining space and although it gives me the correct structure when the listview is expanded, it doesn't work for the list hidden since the cardview fills the space with nothing.
Update
As suggested I have tried changing the root layout to LinearLayout using weight, however, I got the same result as before and if I change the weight of the cardview to 1 and the checkbox to 0 I am able to get the desired layout for the expanded list but not for the hidden case.
<?xml version="1.0" encoding="utf-8"?>
<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:background="#android:color/white"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/card"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
>
<ImageButton
android:layout_width="#dimen/event_invitation_expand_icon"
android:layout_height="#dimen/event_invitation_expand_icon"
android:id="#+id/shrink"
android:src="#drawable/ic_shrink"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/shrink"
android:layout_marginTop="5dp"
android:id="#+id/list">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="ListFragment"
tools:layout="#layout/fragment_list"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/check"
android:id="#+id/check"
android:layout_marginTop="20dp"
android:layout_below="#+id/card"
/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button"
android:textStyle="bold"
android:textColor="#android:color/white"
/>
You'll need to use a LinearLayout and use Weight for the childs.
You can change all views weight on click.
But I think you'll need to put your CheckBox inside a layout and set this layout weight. Otherwise you'll mess with the height.
Didn't look to close to your layout, but you may need to do that for CardView too.
Just keep that in mind.
Hope this helps
To do what you are trying to do, you would have better luck using a LinearLayout with vertical orientation as your root element. Doing this, you could set the CardView to have a weight of 1 (and a 'height' of 0dp, because of how weight works) without giving a weight to the other elements, causing it to fill all available space not taken by the other two elements. The method for doing this can be found here:
http://developer.android.com/guide/topics/ui/layout/linear.html#Weight

ListView line filling half screen

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...

Need help centering an EditText in a Linear Layout

I'm trying to center an edittext vertically and horizontally in a linear layout, but it is not working. Very simple problem really.
<?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="fill_parent"
android:orientation="vertical"
android:background="#drawable/login">
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#drawable/loginbutton"
android:text="Username"
android:layout_gravity="center"
android:textSize="25dp"
android:gravity="center_horizontal|center_vertical"
android:textColor="#000000"
android:layout_margin="10dp"
android:id="#+id/username">
</EditText>
I'll try changing to a relativelayout in the mean time.
LinearLayout do not support centering in the direction it stacks items as far as I know. Unless the LinearLayout is crucial (which in your case it shouldn't be, as you also need the centering), I would recommend you switch to a RelativeLayout.
With a RelativeLayout, you can set the attribute android:layout_centerInParent="true" on the EditText to get it centred.
Using gravity affects the gravity of the contents of said UI item, this means (in this case) that the text inside the EditText would be centered. In order to center the UI item itself you need to define layout_gravity as this is the gravity a UI item holds within his parent. The code posted by the OP will do the horizontal center but not the vertical center.
As an alternative you can use RelativeLayout
<?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="#drawable/login"
android:orientation="vertical" >
<EditText
android:id="#+id/username"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/loginbutton"
android:layout_centerInParent="true"
android:text="Username"
android:textColor="#000000"
android:textSize="25dp" >
</EditText>
</RelativeLayout>
It is very simple. Add android:gravity="center" with the linear layout.
<LinearLayout
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"
android:orientation="vertical"
android:gravity="center"
>
Try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/login"
android:layout_centerVertical="true"
android:layout_centerInParent="true">

problem with android layout

I have the following layout for a custom title bar. However, the problem is this: both the imageview and the imagebutton are coming at the centre. I was expecting the imagebutton to be at the extreme right. Can anyone kindly let me know what I did wrong here ? Thanks.
<?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="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:src="#drawable/header"
android:id="#+id/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
</ImageView>
<ImageButton
android:id="#+id/saveButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/savetap"
android:background="#null"
android:gravity="right"
android:layout_above="#+id/header">
</ImageButton>
</LinearLayout>
Your layout is only 35dip tall, so pressumibly if you show your ImageView the ImageButton gets positioned outside the screen. Consider changing your layout_height to wrap_content, if appropiate.
You're using a vertically oriented LinearLayout, all View will be presented in a vertical fashion. Use a RelativeLayout so that you'll have more control over where Views are positioned. If you'd still like to use a LinearLayout, you'll have to use horizontal orientation so that the Views can be on the same "line".
Use layout_gravity to layout the item to the right, just gravity is used by the contents of the view.
At first if width is set to fill parent it really fills parent so it use all the width.
Second: why not RelativeLayout? It provides more options and control.
Maybe this is what you looking for:
`
<?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="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:src="#drawable/header"
android:id="#+id/header"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="left">
</ImageView>
<ImageButton
android:id="#+id/saveButton"
android:layout_height="wrap_content"
android:src="#drawable/savetap"
android:background="#null"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content" android:layout_alignParentRight="true">
</ImageButton>
</RelativeLayout>
`

Hiding the main layout of Custom Dialog

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.

Categories

Resources