gpt4 book ai didi

android - ConstrainLayout 中的自定义微调器未正确对齐

转载 作者:行者123 更新时间:2023-12-04 11:59:48 26 4
gpt4 key购买 nike

我在 ConstrainLayout 中有一个自定义微调器,微调器选择的值未正确对齐。当我以相对布局显示微调器时,这很有效。我想在约束布局中正确显示
预期产出 (第一项是选定的项目):
This is the expected result
Activity .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>
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"/>

更新 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));
SpinnerAdapter adapter = new SpinnerAdapter(this, R.layout.spinner_layout, R.id.txt, list);
mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
// Stop Location Display

break;
case 1:
// Start Location Display
break;
case 2:
// Re-Center MapView on Location
break;
case 3:
// Start Navigation Mode
break;
case 4:
// Start Compass Mode
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}

});

}
电流输出
Current result

最佳答案

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintVertical_bias="1"
尝试将这四行添加到 XML 中的微调器。

关于android - ConstrainLayout 中的自定义微调器未正确对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69025661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com