0

私が開発している Android 4.1 アプリでは、検索結果リスト ビューのテキストをサムネイルの右側に表示したいと考えています。xml ファイルを解析して結果を取得します。現在、テキストは画像の下に表示されていますが、画像の右側に表示したいです。

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

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent" android:layout_height="0dip"
        android:layout_weight="1" android:drawSelectorOnTop="false"
        />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:contentDescription="@string/description"
        android:gravity="left"
        android:scaleType="fitXY" />

        <TextView
        android:id="@+id/empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:text="" />

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/footer"
        style="@android:style/ButtonBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/prev_10_results"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.14"
            android:text="@string/prev_10_results" />

        <Button
            android:id="@+id/next_10_results"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="@string/next_10_results" />
    </LinearLayout>

    </ScrollView>

    </LinearLayout>

PeopleSearchAdapter.java (これは、xml ファイルから取得した後にコンテンツを表示している場所です)

    public PeopleListView (Context context, String itemName, String itemLocation, String image_url, String kudoRank)
        {
            super (context);
            setOrientation(LinearLayout.VERTICAL);

            LinearLayout.LayoutParams params = new  LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(5, 3, 5, 0);

            image = new ImageView (context);
            Log.v("Image URL: ", image_url);
            if(image_url != null && !(image_url.equals("")))
            {
                try
                {
                    URL url = new URL (image_url);
                    URLConnection conn = url.openConnection();
                    conn.connect();
                    BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
                    Bitmap bm = BitmapFactory.decodeStream (bis);
                    bis.close ();
                    image.setImageBitmap(bm);
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }

            else
            {
                image.setImageResource(R.drawable.no_image);
            }
            addView (image, params);

            name = new TextView (context);
            name.setText(itemName);
            name.setTextSize(16f);
            name.setTextColor(Color.BLACK);
            addView(name, params);

            kudo_rank = new TextView (context);
            kudo_rank.setText(kudoRank);
            kudo_rank.setTextSize(16f);
            kudo_rank.setTextColor(Color.BLACK);
            addView(kudo_rank, params);

            location = new TextView (context);
            location.setText(itemLocation);
            location.setTextSize(16f);
            location.setTextColor(Color.BLACK);
            addView(location, params);

        }

I've attached a screenshot of how the results are being displayed now and just want the three text fields that are displayed below the image right now to be displayed to its right instead.

検索結果ビュー

ありがとう..

4

1 に答える 1

1

ListViewこれを行う最も簡単な方法は、 xmlでレイアウトを定義することです。これが私が使ったものです。私はアプリで同様のことをしました。

これは、リスト ビューが表示される場所です。

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/view" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@drawable/logo"
        android:orientation="vertical" >
    </LinearLayout>

    <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="a15009789e230a7" />
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_above="@+id/adView"
        android:layout_centerHorizontal="true"
        android:background="@drawable/background"
        android:cacheColorHint="#00000000" >
    </ListView>






</RelativeLayout>

これは、ListViewあなたが望むものと同様のレイアウトで定義されている場所です:

    <?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:orientation="horizontal"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/imgThumb"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/diningbutton"
        android:gravity="center_vertical" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/imgThumb"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/diningTitle"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:gravity="top"
            android:paddingTop="5dp"
            android:textColor="#000000"
            android:textSize="16dp"
            android:textStyle="normal" />

        <TextView
            android:id="@+id/listSubHeader"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="bottom"
            android:paddingBottom="5dp"
            android:paddingTop="5dp"
            android:textColor="#000000"
            android:textSize="14dp"
            android:textStyle="italic" />
    </LinearLayout>

</RelativeLayout>

これはアダプターです:

    @Override
protected void onCreate(Bundle savedInstanceState)
{

    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.dining);



    // Create ListData object to hold list data
    ListData newListItem = new ListData();

    try
    {
        // parse data and populate the list view
        this.itemObject = newListItem.getData(DATAURL);
        Log.e(TAG, "item object: " + this.itemObject.toString());
        ListAdapter adapter = new ListAdapter(this, R.layout.dininglistview, this.itemObject);
        // Create listview
        this.listView1 = (ListView) this.findViewById(android.R.id.list);
        this.listView1.setAdapter(adapter);
        GetImagesTask imgTask = new GetImagesTask();
        imgTask.execute(this.itemObject);

        AdView adView = (AdView)this.findViewById(R.id.adView);
        AdRequest re = new AdRequest();
        adView.loadAd(re);

    }
    catch (InterruptedException e)
    {

        Log.e(TAG, "Unexpected error", e);
    }
    catch (ServiceException e)
    {
        AlertDialog alertDialog = new AlertDialog.Builder(DiningActivity.this).create();
        alertDialog.setTitle("Temporarily unavailable");
        alertDialog.setMessage("Please contact top25@uievolution.com");
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            // if there is an error, send the user to the home page
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                Intent homeIntent = new Intent(DiningActivity.this, HomeActivity.class);
                DiningActivity.this.startActivity(homeIntent);

            }
        });
        alertDialog.show();
    }
    // implement dining adapter

}

これが役立つことを願っています!頑張ってください!

于 2012-07-26T21:21:25.163 に答える