我在 ConstrainLayout 中有一个自定义微调器,微调器选定的值未正确对齐。当我以相对布局显示微调器时,这很有效。我想在constrainlayout中正确显示它
预期输出(第一项是所选项目):
活动.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.esri.arcgisruntime.mapping.view.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</com.esri.arcgisruntime.mapping.view.MapView>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:overlapAnchor="false"
android:popupBackground="#00000000"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
spinner_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:textColor="#FFF"
android:textSize="20sp"
android:gravity="right"
android:textStyle="bold|normal"
android:singleLine="true"
android:layout_weight="0.9"/>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_weight="0.1"
android:contentDescription="@null"/>
Run Code Online (Sandbox Code Playgroud)
更新JAVA代码:
ArrayList<ItemData> list = new ArrayList<>();
list.add(new ItemData("Stop", R.drawable.locationdisplaydisabled));
list.add(new ItemData("On", R.drawable.locationdisplayon));
list.add(new ItemData("Re-Center", R.drawable.locationdisplayrecenter));
list.add(new ItemData("Navigation", R.drawable.locationdisplaynavigation));
list.add(new ItemData("Compass", R.drawable.locationdisplayheading)); …Run Code Online (Sandbox Code Playgroud) 我试图了解像这样在CardView侧面设置颜色的最佳方法是什么
我的cardview看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"
card_view:cardCornerRadius="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
.....
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud) 我有一个RecyclerView显示学生详细信息的列表。我面临的问题是当我单击第一项时,它会返回第二项的数据。我相信这与 有关getAdapterPosition(),但我不确定。
在这种情况下,它会在选择第一个学生时返回第二个学生(项目)的卷号。
任何帮助表示赞赏
回收器视图适配器
public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.ViewHolder> {
Context context;
public List<StudentDataModel> dataModels;
public StudentDataModel dataAdapter;
public StudentAdapter(List<StudentDataModel> getDataAdapter, Context context){
super();
this.dataModels = getDataAdapter;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.student, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(final StudentAdapter.ViewHolder viewHolder, final int position) {
dataAdapter = dataModels.get(position);
viewHolder.NameStudentCard.setText(dataAdapter.getName());
viewHolder.RankStudentCard.setText(dataAdapter.getRank());
viewHolder.RollStudentCard.setText(dataAdapter.getRoll());
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void …Run Code Online (Sandbox Code Playgroud)