代码之家  ›  专栏  ›  技术社区  ›  YVS1102

如何使自定义微调器与默认微调器相似?

  •  1
  • YVS1102  · 技术社区  · 8 年前

    所以,我有一个表中的数据,所以我使用适配器。下面是我如何在适配器中设置它

    public View getView(int position, View convertView, ViewGroup parent) {
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        View row = inflater.inflate(R.layout.list_item, parent,false);
        // get your views here and set values to them
    
        TextView ItemCodetextview = (TextView) row.findViewById(R.id.itemcode);
        TextView ItemNametextview = (TextView) row.findViewById(R.id.itemname);
    
        GenerateItemdoModel current = dataModels.get(position);
    
        ItemCodetextview.setText(current.getItemCode());
        ItemNametextview.setText(current.getItemName());
    
        return row;
    }
    

    list\u项目

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_marginTop="20sp"
        android:layout_marginRight="20sp"
        android:layout_height="wrap_content">
    
        <TextView
            android:layout_width="wrap_content"
            android:id="@+id/itemcode"
            android:textSize="12sp"
            android:text="1"
            android:textStyle="bold"
            android:layout_marginLeft="20sp"
            android:ellipsize="marquee"
            android:layout_height="wrap_content" />
    
        <TextView
            android:layout_width="wrap_content"
            android:id="@+id/itemname"
            android:layout_marginLeft="20sp"
            android:text="2"
            android:textSize="12sp"
    
            android:ellipsize="marquee"
            android:textStyle="bold"
    
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    xml中的微调器

    <LinearLayout
        android:layout_marginLeft="20sp"
        android:layout_width="fill_parent"
        android:orientation="horizontal"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:text="Item Code"
            android:textStyle="bold"
            android:layout_gravity="center"
            android:gravity="center"
            android:textSize="12sp"
            android:layout_height="match_parent" />
    
        <Spinner
            android:id="@+id/itemcodeval"
            android:layout_width="match_parent"
            android:textStyle="bold"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40sp"
            android:layout_marginStart="40sp"/>
    
        <EditText
            android:id="@+id/valueitemcde"
            android:layout_width="wrap_content"
            android:visibility="gone"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    我的默认微调器(不带适配器)

    <LinearLayout
        android:layout_marginTop="30sp"
        android:layout_marginLeft="20sp"
        android:orientation="horizontal"
    
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:text="Tipe Rijek"
            android:layout_gravity="center"
            android:textStyle="bold"
            android:gravity="center"
            android:textSize="12sp"
            android:layout_height="match_parent" />
    
        <Spinner
            android:id="@+id/tipeval"
            android:layout_width="match_parent"
            android:textStyle="bold"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40sp"
            android:layout_marginStart="40sp"
            />
        <EditText
            android:id="@+id/valuetipe"
            android:layout_width="wrap_content"
            android:visibility="gone"
            android:textSize="12sp"
            android:layout_height="wrap_content" /> </LinearLayout>
    

    这是带有适配器的自定义微调器的屏幕截图

    enter image description here

    这是默认微调器

    enter image description here

    因此,我的问题是如何使自定义微调器看起来像默认微调器?提前谢谢,对不起我的英语

    2 回复  |  直到 8 年前
        1
  •  2
  •   Gowthaman M manas.abrol    8 年前

    在微调器中使用此选项

    style="@android:style/Widget.Holo.Light.Spinner"
    

    参考号: https://developer.android.com/guide/topics/ui/look-and-feel/themes.html

    (或)

    使用此

    添加小型 属性 android:spinnerMode="dialog"

        2
  •  1
  •   Gowthaman M manas.abrol    8 年前

    在里面 list\u项目。xml :

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingLeft="5dp"
        android:layout_height="wrap_content">
    

    在中添加填充 主要布局图 在项目布局中。