image button is not displayed in linear layout
In my app there is a list view with following controls (imageview, textviews, image buttons) nested:
all they are displayed except the "Buy" image button
How to show the "Buy" image button in the list view? I also could not write an action for play and detail image buttons in the list view. Please help me.
my xml is as follows:
<?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" android:background="#ffffff">
<ListView android:id="@+id/list" android:layout_width="1px"
android:layout_height="1px" android:layout_weight="1">
</ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ffffff">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/img" android:layout_width="60dp"
android:layout_height="60dp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:text="fffff"
android:id="@+id/title" android:singleLine="false" android:layout_marginRight="20dp" android:layout_marginLeft="20dp"
android:layout_height="wrap_content" android:textStyle="bold" />
<TextView android:layout_width="wrap_content" android:text="dskbdskkdsvsvsvvvfff"
android:layout_height="wrap_content" android:layout_marginRight="20dp" android:layout_marginLeft="20dp"
android:id="@+id/title2"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:开发者_StackOverflow社区layout_marginLeft="50dp"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageButton android:background="@drawable/play_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/imageButton1">
</ImageButton>
<ImageButton android:background="@drawable/details_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="25dp" android:id="@+id/imageButton2">
</ImageButton>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="left">
<ImageButton android:background="@drawable/buy_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/imageButton3">
</ImageButton>
</LinearLayout>
</LinearLayout>
Try out with this and see. I have modified your xml. Drawables please change. I have used the default icon.png as of now. Then as per your any further requirement change the file. RelativeLayout is the easiest way for us to place widgets. So try using that.
<?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="100dp"
android:background="#ffffff">
<ImageView android:id="@+id/img" android:layout_width="60dp"
android:background="@drawable/icon" android:layout_height="fill_parent"
android:layout_centerVertical="true" />
<LinearLayout android:orientation="vertical"
android:layout_toRightOf="@+id/img" android:layout_width="200dp"
android:layout_height="wrap_content" android:id="@+id/textLL"
android:layout_marginLeft="10dp">
<TextView android:layout_width="wrap_content" android:text="fffff"
android:id="@+id/title" android:layout_height="wrap_content"
android:textStyle="bold" />
<TextView android:layout_width="wrap_content"
android:text="dskbdskkdsvsvsvvvfff dfsdfg sdrfsdgfsdf dfsdfdsf dsgfsdfgg"
android:layout_height="wrap_content" android:id="@+id/title2" />
<LinearLayout android:orientation="horizontal"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton android:background="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/imageButton2" android:layout_weight="0.5" />
<ImageButton android:background="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/imageButton3" android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>
<ImageButton android:background="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:id="@+id/imageButton1" android:layout_toRightOf="@+id/textLL" />
</RelativeLayout>
精彩评论