【发布时间】:2018-03-25 17:35:13
【问题描述】:
我想要这样的布局:
这是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I. ISI PELATIHAN"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="1. "
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Kejelasan tujuan dan manfaat pelatihan"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="2. "
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Penampilan bahan/materi pelatihan"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="3. "
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Kelengkapan bahan/materi pilihan"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="4. "
/>
<TextView
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Metode yang digunakan membantu pemahaman isi program"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="5. "
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Saya mengerti/memahami program/materi yang diberikan"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="6. "
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Saya belajar sesuatu yang baru dari materi yang diberikan"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="7. "
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=" Efisiensi penggunaan waktu"
/>
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="right"/>
</LinearLayout>
</LinearLayout>
结果是:
我想知道的是:
- 如何在行号之前和 RatingBar 之后添加填充?
- 我在文本上使用 wrap_content。对于较短的文本似乎还可以,但对于较长的文本,它就搞砸了。如何将所有文本设置为使用相同的长度,如果文本长度超过某个值,它将被正确包装,如第一张图片所示?
【问题讨论】:
-
您已将
RatingBar属性numStars设置为 5,因此宽度将由该值定义 --> 因此您不应将layout_width设置为match_parent尝试使用wrap_content.然后将每一行包装在RelativeLayout中,而不是LinearLayout。现在将TextView固定到父级 (RelativeLayout) 的开头并在RateBar处结束。现在将RatingBar固定到父级(RelativeLayout)的末尾 -
嗨@Barns。嗯,我仍然很难理解这一点。您介意提供一些示例代码吗?
-
我添加一个例子。看一看。希望对您有所帮助。
标签: android android-layout textview