每当我在 xml 文件中用水平滚动视图标签附上我的自定义视图时,视图似乎消失了。在之前的相关问题中,它被称为
“如果您为内部容器设置 android:layout_gravity="center_horizontal",水平滚动视图将隐藏其子项。”
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp">
<com.example.mahikanthnag.cs.views.StateProgressBar
android:id="@+id/your_state_progress_bar_id"
android:layout_width="200dp"
android:layout_height="wrap_content"
app:spb_currentStateNumber="three"
app:spb_maxStateNumber="four"
app:spb_stateBackgroundColor="#BDBDBD"
app:spb_stateForegroundColor="#009688"
app:spb_stateNumberBackgroundColor="#808080"
app:spb_stateNumberForegroundColor="#eeeeee"
app:spb_currentStateDescriptionColor="#009688"
app:spb_stateDescriptionColor="#808080"
app:spb_animateToCurrentProgressState="true"
app:spb_checkStateCompleted="true"
/>
<com.example.mahikanthnag.cs.views.StateProgressBar
android:id="@+id/your_state_progress_bar_id1"
android:layout_width="200dp"
android:layout_height="wrap_content"
app:spb_currentStateNumber="three"
app:spb_maxStateNumber="four"
app:spb_stateBackgroundColor="#BDBDBD"
app:spb_stateForegroundColor="#009688"
app:spb_stateNumberBackgroundColor="#808080"
app:spb_stateNumberForegroundColor="#eeeeee"
app:spb_currentStateDescriptionColor="#009688"
app:spb_stateDescriptionColor="#808080"
app:spb_animateToCurrentProgressState="true"
app:spb_checkStateCompleted="true"
android:layout_toRightOf="@+id/your_state_progress_bar_id"
/>
<com.example.mahikanthnag.cs.views.StateProgressBar
android:id="@+id/your_state_progress_bar_id2"
android:layout_width="200dp"
android:layout_height="wrap_content"
app:spb_currentStateNumber="three"
app:spb_maxStateNumber="four"
app:spb_stateBackgroundColor="#BDBDBD"
app:spb_stateForegroundColor="#009688"
app:spb_stateNumberBackgroundColor="#808080"
app:spb_stateNumberForegroundColor="#eeeeee"
app:spb_currentStateDescriptionColor="#009688"
app:spb_stateDescriptionColor="#808080"
app:spb_animateToCurrentProgressState="true"
app:spb_checkStateCompleted="true"
android:layout_toRightOf="@+id/your_state_progress_bar_id1"
/>
</RelativeLayout>
</HorizontalScrollView>
但就我而言,我根本没有 android:layout_gravity 属性。我该如何解决这个问题?
这是我在其中添加了 cutom 视图的布局 xml 文件
欢迎任何建议谢谢
使用线性布局而不是相对布局,如下所示:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:id="@+id/travelGallery"
android:layout_width="100dp"
android:layout_height="100dp"
android:gravity="center"
android:orientation="horizontal" >
<Your view 1/>
<Your view 2/>
<Your view n/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句