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>

私はこの問題を抱えています:
私はリストを手に入れました、そして画面の下部でそれらは常にとであるはずEditTextですbutton。しかし、これをレイアウトに追加してアプリを起動するEditTextと、とbuttonがすべてrowに配置されます。写真を参照 してください。

これが(悪い)方法です:

今はどうですか(悪い)

これがどうあるべきかです:

それがどうあるべきか

この問題が解決することを期待していたので、レイアウトaを取得しましたが、RelativeLayout修正されませんでした。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.xmlを膨らませます。main.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>

基本的に、レイアウトを拡張する際には、2つのxmlファイルが必要です.1つはmain.xml(list_mobile.xml)で、もう1つは拡張されたxmlです。

于 2012-08-14T07:35:56.423 に答える