[英]Android: spacing and TextView wrapping issue
我想要这样的布局:
这是我的代码:
<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>
结果是:
我想知道的是:
在guildLine的帮助下使用约束布局和单独的评级栏
您可以在一种布局中设置所有视图。
使用最新的Beta版依赖性
编译'com.android.support.constraint:constraint-layout:1.1.0-beta5'
这里示例教程
https://constraintlayout.com/basics/
官方教程
https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html
这是带有guideLine的ConstraintLayout的示例代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context="android.itomerbu.layoutdemo.MainActivity">
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.44"/>
<TextView
android:id="@+id/btnThird"
android:layout_width="0dp"
app:layout_constraintHorizontal_weight="1"
android:layout_height="wrap_content"
android:text="@string/btnThird"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintRight_toLeftOf="@+id/btnTwoThirds"
app:layout_constraintBottom_toTopOf="@+id/guideline"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"/>
<RatingBar
android:id="@+id/btnTwoThirds"
app:layout_constraintHorizontal_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/btnTwoThirds"
app:layout_constraintBottom_toBottomOf="@+id/btnThird"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btnThird"/>
</android.support.constraint.ConstraintLayout>
您可以使用RelativeLayout
实现所需的功能。 将此xml布局示例插入xml布局文件中。 您可以根据需要更改id
,并根据需要使用填充和边距。 添加尽可能多RelativeLayout
根据您的需要为您团体Activity
。
如果您有任何问题或疑问,请告诉我。
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
>
<TextView
android:id="@+id/tvFirst"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:paddingEnd="4dp"
android:paddingStart="4dp"
android:text="1"
android:textAlignment="center"/>
<TextView
android:id="@+id/tvFirstTitle"
android:text="@string/SomeTextString"
android:layout_toEndOf="@id/tvFirst"
android:layout_toStartOf="@id/rBarFirst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<RatingBar
android:id="@+id/rBarFirst"
style="@style/Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:numStars="5"
android:stepSize="1"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
>
<TextView
android:id="@+id/tvSecond"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:paddingEnd="4dp"
android:paddingStart="4dp"
android:text="2"
android:textAlignment="center"/>
<TextView
android:id="@+id/tvSecondTitle"
android:text="@string/SomeTextString"
android:layout_toEndOf="@id/tvSecond"
android:layout_toStartOf="@id/rBarSecond"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<RatingBar
android:id="@+id/rBarSecond"
style="@style/Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:numStars="5"
android:stepSize="1"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
>
<TextView
android:id="@+id/tvThird"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:paddingEnd="4dp"
android:paddingStart="4dp"
android:text="3"
android:textAlignment="center"/>
<TextView
android:id="@+id/tvThirdTitle"
android:text="@string/SomeTextString"
android:layout_toEndOf="@id/tvThird"
android:layout_toStartOf="@id/rBarThird"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<RatingBar
android:id="@+id/rBarThird"
style="@style/Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:numStars="5"
android:stepSize="1"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
</LinearLayout>
请注意:
我只是注意到您正在使用: style="?android:attr/ratingBarStyleSmall"
您可能需要更改示例中使用的RatingBar
的style
,以与您的应用程序兼容!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.