0

我遇到了这段代码的问题:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        textView.setText(values[position]);

        // Change icon based on name
        String s = values[position];

        System.out.println("s = "+s);
        System.out.println("Results = "+name[2].toString());
        for (int i = 0; i < name.length; i ++){
            if (s.equals(name[i])) {
                imageView.setImageDrawable(loadImageFromURL("http://10.0.0.117/test/"+s+".jpg", "iOS"));
            }
        }
        return rowView;
    }

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/logo"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="5dp"
        android:contentDescription="@string/desc"
        android:src="@drawable/windowsmobile_logo" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/logo"
        android:layout_marginBottom="16dp"
        android:layout_toRightOf="@+id/logo"
        android:text="@+id/label"
        android:textSize="20dp" />


    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >



        <Button
            android:id="@+id/btn_zoeken"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/txt_zoeken"
            android:text="@string/Zoeken" />

        <EditText
            android:id="@+id/txt_zoeken"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>
    </RelativeLayout>

</RelativeLayout>

我遇到了这个问题:
我有一个列表,在屏幕底部,它们应该始终是 anEditText和 a button。但是当我在布局中添加它并启动应用程序时,它会将EditTextand放置button在 everyrow中,请参见图片:

这就是它的样子(坏的):

现在怎么样(坏)

应该是这样的:

应该如何

我进入了 a RelativeLayoutin a的布局RelativeLayout,因为我希望它能解决这个问题,但它没有。

请注意,我在相对布局中制作了一个列表,所以我不使用 ListView。
任何人都有解决方案或建议如何解决这个问题?

我希望我的问题很清楚。

已经谢谢了, Bigflow

编辑1:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.inflater, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        Button btn_zoeken = (Button) rowView.findViewById(R.id.button1);
        textView.setText(values[position]);

        // Change icon based on name
        String s = values[position];

        System.out.println("s = "+s);
        System.out.println("Results = "+name[2].toString());
        for (int i = 0; i < name.length; i ++){
            if (s.equals(name[i])) {
                imageView.setImageDrawable(loadImageFromURL("http://10.0.0.117/test/"+s+".jpg", "iOS"));
            }
        }
        return rowView;
    }
4

1 回答 1

1

按照建议使用文件中的按钮(即 btn_zoeken)和图像(即 txt_zoeken)main.xml作为页脚。并Mohasin Naeem使用它android:layout_alignParentBottom="true"

并膨胀你list_mobile.xmlmain.xml布局文件。

所以你list_mobile.xml应该看起来像这样。

 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <EditText
      android:id="@+id/editText1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_toLeftOf="@+id/button1" />

  <Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:text="Button" />

</RelativeLayout>

btn_zoeken 和 txt_zoeken 应该在主屏幕的底部。你膨胀的 layout.xml 应该如下所示。

    <RelativeLayout 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/logo"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="5dp"
    android:contentDescription="@string/desc"
    android:src="@drawable/windowsmobile_logo" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/logo"
    android:layout_marginBottom="16dp"
    android:layout_toRightOf="@+id/logo"
    android:text="@+id/label"
    android:textSize="20dp" />
 </RelativeLayout>

基本上,在膨胀布局时,您需要两个 xml 文件。一个是您的main.xml(list_mobile.xml),另一个是您的膨胀 xml

于 2012-08-14T07:35:56.423 回答