制作一个评价界面
话不多说,先上效果图
首先先看看界面设计,本人采用的是垂直线性布局,通过多个水平线性布局的引入来完成位置设置,通过android layout_weight="?"来设置,其中?表示比例(整形)
界面中要设置一张用户图片(ImageView),和输入框EditText,其次,是ImageButton图片按钮当点击它时跳转到相册,这里就不演示了(Intent至关重要),请各位记得加入uri权限
最后几个星级评分条,CheckBox复选框,和Button按钮进行点击事件
上代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
//orientation是设置方向vertical为垂直,horizontal为水平
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">//水平线性布局,其中,layout_height是要分的比例,通过layout_weight="整形(int)"
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="发表评价"
android:textSize="45dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/shangp" />
//设置图片,一般较为方便的话建议各位拖控件
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:hint="请写下对商品的感受吧,对他人帮助很大!"
android:textSize="40dp" />
//输入框,hint是提示文字,注意textSize根据机型自己设置
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#fff"
app:srcCompat="@drawable/tup" />
//设置图片按钮,在background中#111为黑色,#fff为白色,#bbb为灰色,其他颜色可单机左边进行调换
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:text="团体综合满意度"
android:textColor="#111"
android:textSize="40dp" />
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="50dp"
android:numStars="5"
android:rating="0" />
//星级评分条,numStars设置有多少颗星星,rating设置默认是由多少星星是选中状态为浮点数,marginRiaht是设置右边间距
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:background="#317B7B7C"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="店铺评分"
android:textColor="#111"
android:textSize="50dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="商家服务诚信度"
android:textColor="#111"
android:textSize="40dp" />
<RatingBar
android:id="@+id/ratingBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:numStars="5"
android:rating="0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="服务态度"
android:textColor="#111"
android:textSize="40dp" />
<RatingBar
android:id="@+id/ratingBar3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="50dp"
android:numStars="5"
android:rating="0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.5"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:text="匿名评价"
android:textSize="40dp" />
//复选框
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DD714D"
android:text="发表评价"
android:textColor="#fff"
android:textSize="30dp" />
</LinearLayout>
</LinearLayout>
以上已经注释过了,如果还有什么不会的,欢迎提问
另外要注意的是RatingBar(星级评分条)宽度width要设置为自适应(wrap_content)否则星星数量将会不受控制
最后在MainAcitivity.java
RatingBar(星级评分条)设置OnRatingBarChangeListener事件,然后重写下onRatingChanged()方法
其余设置点击事件或进行Activity之间的传递
备注:uri权限为
<!--拍照-->
<uses-permission android:name="android.permission.CAMERA" />
<!--读写-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.PERMISSIONS_STORAGE"/>
祝好!