
效果圖.gif
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DFE6E0"
android:orientation="vertical">
<RelativeLayout
android:background="#fff"
android:id="@+id/rl_survey"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="測評"
android:textColor="@android:color/black"
android:textSize="20sp"/>
</RelativeLayout>
<LinearLayout
android:layout_below="@id/rl_survey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:textSize="20sp"
android:layout_margin="10dp"
android:textColor="#000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是標題"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:id="@+id/check_item1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/check_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_white"/>
<TextView
android:id="@+id/check_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="我是文本"/>
</LinearLayout>
<LinearLayout
android:id="@+id/check_item2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/check_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_white"/>
<TextView
android:id="@+id/check_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="我是文本"/>
</LinearLayout>
<LinearLayout
android:id="@+id/check_item3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/check_image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_white"/>
<TextView
android:id="@+id/check_text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="我是文本"/>
</LinearLayout>
<LinearLayout
android:id="@+id/check_item4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/check_image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_white"/>
<TextView
android:id="@+id/check_text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="我是文本"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/pre"
android:padding="10dp"
android:textColor="#2F70C1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上一步"/>
<TextView
android:id="@+id/tv_page"
android:padding="10dp"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:text="1/10"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:text="提交問卷"
android:layout_marginBottom="20dp"
android:textColor="@android:color/white"
android:visibility="invisible"
android:background="@drawable/survey_commit"/>
</RelativeLayout>
/**
* Created by zhangyapeng on 2018/10/26.
*/
class SurveyBean {
private String title;
private String[] sel;
public SurveyBean(String title, String[] sel) {
this.title = title;
this.sel = sel;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String[] getSel() {
return sel;
}
public void setSel(String[] sel) {
this.sel = sel;
}
}
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@BindView(R.id.rl_survey)
RelativeLayout mRlSurvey;
@BindView(R.id.title)
TextView mTitle;
@BindView(R.id.check_image1)
ImageView mCheckImage1;
@BindView(R.id.check_text1)
TextView mCheckText1;
@BindView(R.id.check_item1)
LinearLayout mCheckItem1;
@BindView(R.id.check_image2)
ImageView mCheckImage2;
@BindView(R.id.check_text2)
TextView mCheckText2;
@BindView(R.id.check_item2)
LinearLayout mCheckItem2;
@BindView(R.id.check_image3)
ImageView mCheckImage3;
@BindView(R.id.check_text3)
TextView mCheckText3;
@BindView(R.id.check_item3)
LinearLayout mCheckItem3;
@BindView(R.id.check_image4)
ImageView mCheckImage4;
@BindView(R.id.check_text4)
TextView mCheckText4;
@BindView(R.id.check_item4)
LinearLayout mCheckItem4;
@BindView(R.id.pre)
TextView mPre;
@BindView(R.id.tv_page)
TextView mTvPage;
@BindView(R.id.submit)
Button mSubmit;
// 設(shè)置初始位置,獲取第一條數(shù)據(jù)
public static int possition = 0;
// 存儲數(shù)據(jù)的集合
private List<SurveyBean> beanAar = new ArrayList<>();
// 記錄分數(shù)
private int[] checkPossition = new int[]{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
// 4張圖片
private ImageView[] mImageViews;
private Handler mHandler = new Handler();
// 計算總分數(shù)
private int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mImageViews = new ImageView[]{mCheckImage1, mCheckImage2, mCheckImage3, mCheckImage4};
mCheckItem1.setOnClickListener(this);
mCheckItem2.setOnClickListener(this);
mCheckItem3.setOnClickListener(this);
mCheckItem4.setOnClickListener(this);
mPre.setOnClickListener(this);
mSubmit.setOnClickListener(this);
possition = 0;
init();
setDatas();
}
private void setDatas() {
mTitle.setText(beanAar.get(possition).getTitle());
mCheckText1.setText(beanAar.get(possition).getSel()[0]);
mCheckText2.setText(beanAar.get(possition).getSel()[1]);
mCheckText3.setText(beanAar.get(possition).getSel()[2]);
mCheckText4.setText(beanAar.get(possition).getSel()[3]);
mTvPage.setText(possition + 1 + "/10");
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.check_item1:
checkPossition[possition] = 0;
hide(0);
next();
break;
case R.id.check_item2:
checkPossition[possition] = 1;
hide(1);
next();
break;
case R.id.check_item3:
checkPossition[possition] = 2;
hide(2);
next();
break;
case R.id.check_item4:
checkPossition[possition] = 3;
hide(3);
next();
break;
case R.id.pre:
pre();
break;
case R.id.submit:
Log.v("666", score+"");
Toast.makeText(MainActivity.this, "score" + score, Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
private void next() {
possition += 1;
if (possition > 9) {
possition = 9;
addScore();
mSubmit.setVisibility(View.VISIBLE);
return;
}
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
hide();
setDatas();
}
}, 300);
}
/**
* 上一步
*/
private void pre() {
possition -= 1;
if (possition < 0) {
possition = 0;
}
if (possition < 9) {
mSubmit.setVisibility(View.INVISIBLE);
}
hide(checkPossition[possition]);
setDatas();
}
private void addScore() {
for (int i = 0; i < checkPossition.length; i++) {
if (checkPossition[i] == -1) {
score = 0;
return;
}
}
for (int i = 0; i < checkPossition.length; i++) {
switch (checkPossition[i]) {
case 0:
score += 10;
break;
case 1:
score += 8;
break;
case 2:
score += 6;
break;
case 3:
score += 3;
break;
default:
break;
}
}
}
private void hide(int i) {
for (int i1 = 0; i1 < mImageViews.length; i1++) {
if (i1 == i) {
mImageViews[i1].setImageResource(R.drawable.button_orange_1);
} else {
mImageViews[i1].setImageResource(R.drawable.button_white);
}
}
}
private void hide() {
for (int i1 = 0; i1 < mImageViews.length; i1++) {
mImageViews[i1].setImageResource(R.drawable.button_white);
}
}
public void init() {
beanAar.add(new SurveyBean("1、您的年齡:", new String[]{"18--30歲", "31-45歲", "46-55歲", "55歲以上"}));
beanAar.add(new SurveyBean("2、您的身體健康狀況:", new String[]{"非常好", "好", "一般", "差"}));
beanAar.add(new SurveyBean("3、您的投資年限", new String[]{"10年以上", "5-10年", "1-5年", "1年內(nèi)"}));
beanAar.add(new SurveyBean("4、您的投資經(jīng)驗可以被概括為:", new String[]{"豐富:是一位積極和有經(jīng)驗的證券投資者,并傾向于自己作出投資決定", "一般:具有一定的證券投資經(jīng)驗,需要進一步的指導", "有限:有過購買國債,貨幣型基金等保本型金融產(chǎn)品投資經(jīng)驗", "無:除銀行活期和投定期儲蓄存款外,基本沒有其他資經(jīng)驗"}));
beanAar.add(new SurveyBean("5、您曾經(jīng)或正在做的投資產(chǎn)品(若有多項請選風險最大的一項):", new String[]{"期貨、權(quán)證", "股票", "債券、基金", "無"}));
beanAar.add(new SurveyBean("6、今后5年內(nèi)您的預期收入:", new String[]{"預期收入將逐漸增加", "預期收入將保持穩(wěn)定", "預期收入將不斷減少", "無"}));
beanAar.add(new SurveyBean("7、以下哪項描述最符合您的投資態(tài)度?", new String[]{"希望賺取高回報,愿意為此承擔較大本金損失", "尋求資金的較高收益和成長性,愿意為此承擔有限本金損失", "保守投資,不希望本金損失,愿意承擔一定幅度的收益波動", "厭惡風險,不希望本金損失,希望獲得穩(wěn)定回報"}));
beanAar.add(new SurveyBean("8、您用于投資的資金在您的總資產(chǎn)中占比大致是多少(除自用和經(jīng)營性財產(chǎn)外)?", new String[]{"大于50%", "30%~50%", "10%~30%", "小于10%"}));
beanAar.add(new SurveyBean("9、您在投資中能夠接受的最大本金損失大致是多少?", new String[]{"最大本金虧損50%以上", "最大本金虧損20%~50%", "最大本金虧損5%~20%", "最大本金虧損5%以內(nèi)"}));
beanAar.add(new SurveyBean("10.您的投資目的是?", new String[]{"關(guān)心長期的高回報,能夠接受短期的資產(chǎn)價值波動", "傾向長期的成長,較少關(guān)心短期的回報以及波動", "希望投資能獲得一定的增值,同時獲得波動適度的年回報", "只想確保資產(chǎn)的安全性,同時希望能夠得到固定的收益"}));
}
}

button_orange_1.png

button_white.png

survey_commit.jpg