每当我在xml文件中附加带有水平滚动视图标签的自定义viewws时,视图似乎消失了。 在之前的相关问题中,它被称为
“如果设置,水平滚动视图会隐藏其子项 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属性。我该如何解决这个问题?
这是我的布局xml文件,其中我添加了cutom视图
欢迎任何建议 感谢
答案 0 :(得分:0)
使用线性布局代替相对布局,如下所示:
<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>