图像按钮不以线性布局显示

时间:2011-06-07 10:57:49

标签: android android-layout

在我的应用程序中,有一个列表视图,其中嵌套了以下控件(imageview,textviews,图像按钮):

enter image description here

除了“购买”图像按钮

外,它们都会显示

enter image description here

如何在列表视图中显示“购买”图像按钮? 我也无法在列表视图中为播放和细节图像按钮编写动作。请帮帮我。

我的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"  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: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>

1 个答案:

答案 0 :(得分:0)

试试这个并看看。我修改了你的xml。 Drawables请改变。我现在使用了default icon.png。然后根据您的任何进一步要求更改文件。 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="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>
相关问题