android - ListView 的弧形边框

标签 android

我是 android 和 java 的新手,我需要在 android 中创建一个简单的应用程序。我在这个 Activity 中有一个 Activity 页面。这是我的 Activity 页面

package com.tkcmu.dev;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class tkcmu extends Activity {
    private ListView lv1;

    @Override
        public void onCreate(Bundle icicle)
        {
        super.onCreate(icicle);
        setContentView(R.layout.main);


        ArrayList<String> listItems = new ArrayList<String>();

        try {
            URL recentUrl = new URL(
                    "To some link");
            URLConnection tc = recentUrl.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));

            String line;
            while ((line = in.readLine()) != null) {
                JSONArray ja = new JSONArray(line);

                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo = (JSONObject) ja.get(i);
                    listItems.add(jo.getString("content"));
                }
            }

    }catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }catch (IOException e) {
                e.printStackTrace();

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        lv1=(ListView)findViewById(R.id.ListView01);
        // By using setAdpater method in listview we an add string array in list.
        lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , listItems));
        }
}

我的main.xml是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="10sp"
        android:layout_marginRight="10sp"
        android:layout_marginTop="10sp"
        android:layout_weight="1"
        android:background="@drawable/customshape"
        android:cacheColorHint="#FFFFFF"
        android:clickable="true"
        android:clipToPadding="true"
        android:dividerHeight="1px"
        android:drawSelectorOnTop="false"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:footerDividersEnabled="true"
        android:headerDividersEnabled="true"
        android:longClickable="true" />
</LinearLayout>

我还有一个 customshape.xml 在 drawable 中,它是

 <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="10dp" />
</shape>

我得到的结果是整个自定义列表部分都弯曲了,但我想让每一行的背景都弯曲。我已经在此处发布了我的整个代码(不包括 AndroidManifest.xml),所以如果有人告诉我我需要在此代码中进行哪些更改,我将不胜感激。任何机构都知道如何实现它。

最佳答案

添加

 android:background="@drawable/customshape" 

到 listview row.xml 文件的 Root View 而不是将它应用到 listview

关于android - ListView 的弧形边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5871228/

相关文章:

java - 当 ViewPager 从右向左滚动时,LinearInterpolator 无法正常工作

android - 在 android 上调用拦截

Android Room 使用 Migration 更改列的类型

java - 如何更改共享首选项中的值

android - android中的画廊类型 ScrollView

android - 退款后无法在 Google Play 上重新购买应用内结算项目

java - 互联网连接重新启动时 Websocket 不工作

java - 无法解析输入: keystore

java - 使用 Adob​​e Air 构建 Android 原生库

java - 如何获取两个日期之间的通话记录数据和日期之间的来电和去电总数