ProgressBar未出现在Android应用程序中
我正在开发一个控制Arduino Uno的应用程序,它可以从连接到模拟输入引脚的传感器获取数据 我想在一个水平条中显示它们的值,所有这些值都在彼此下面 我的activity_main.xml如下所示:ProgressBar未出现在Android应用程序中,android,Android,我正在开发一个控制Arduino Uno的应用程序,它可以从连接到模拟输入引脚的传感器获取数据 我想在一个水平条中显示它们的值,所有这些值都在彼此下面 我的activity_main.xml如下所示: <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <Line
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/tempLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="100">
<TextView
android:id="@+id/tempLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:layout_gravity="end"
android:textAlignment="viewEnd"
android:text="Temperature = " />
<TextView
android:id="@+id/tempValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="20 °C" />
</LinearLayout>
<LinearLayout
android:id="@+id/lightLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:padding="10dp">
<TextView
android:id="@+id/lightLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="viewEnd"
android:layout_gravity="end"
android:text="Light: "
android:layout_weight="15"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="@+id/lightBar"
android:padding="5dp"
android:layout_weight="75"
android:progress="50"
android:max="100"
android:minHeight="10dp" />
<TextView
android:id="@+id/lightValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="50%"/>
</LinearLayout>
<LinearLayout
android:id="@+id/waterLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:padding="10dp">
<TextView
android:id="@+id/waterLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="viewEnd"
android:layout_gravity="end"
android:text="Water: "
android:layout_weight="15"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="@+id/waterBar"
android:padding="5dp"
android:layout_weight="75"
android:progress="50"
android:max="100"
android:minHeight="10dp" />
<TextView
android:id="@+id/waterValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50%"
android:layout_weight="10"/>
</LinearLayout>
<LinearLayout
android:id="@+id/gasLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:padding="10dp">
<TextView
android:id="@+id/gasLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="viewEnd"
android:layout_gravity="end"
android:text="Gas: "
android:layout_weight="15"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:padding="5dp"
android:id="@+id/gasBar"
android:layout_weight="75"
android:progress="50" />
<TextView
android:id="@+id/gasValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="50%"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
问题是,当我在手机上运行应用程序时,这些条不会显示出来
如何解决此问题
以下是显示应用程序的快照,在此渲染中,条形图正常显示:
您已将进度条的高度设置为10dp,填充为5dp。这意味着paddingTop=5dp和paddingBottom=5dp,没有足够的空间来查看进度条
您应该稍微增加进度条的高度,例如20dp。希望能帮助你 您已经设置了android:layout\u height=“10dp”。你试过增加它的高度吗?当然有,但是没有用。我也试过从onCreate()设置它们:lightBar=(ProgressBar)findViewById(R.id.lightBar);lightBar.setVisibility(View.VISIBLE);waterBar=(ProgressBar)findViewById(R.id.waterBar);waterBar.setVisibility(视图.可见);gasBar=(ProgressBar)findviewbyd(R.id.gasBar);gasBar.setVisibility(View.VISIBLE)@马哈茂德·马哈迪:我使用了你的布局,进度条显示在我的末端。你可以发布你的输出。