【发布时间】:2018-08-21 08:33:38
【问题描述】:
所以,我有一个来自我的表的数据,所以我正在使用适配器。这是我在适配器中的设置方式
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_item
<?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>
这是带有适配器的自定义微调器的屏幕截图
这是默认的微调器
所以,我的问题是如何让我的自定义微调器看起来像默认微调器?在此先感谢,对不起我的英语
【问题讨论】:
-
在 list_item.xml 文件中为
LinearLayout父级添加顶部和底部填充
标签: android android-layout android-spinner