代码如下:
package fraction;
import com.chinasofti.smartclassroomtv.ResourceTable;
import com.chinasofti.smartclassroomtv.data.*;
import com.chinasofti.smartclassroomtv.demain.Question;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.render.Region;
import java.util.ArrayList;
import java.util.List;
public class Question_bank extends Fraction {
private ListContainer listContainer;
private Button aft;
private Button pre;
private Button search_btn;
private Button return_btn;
private Button show_add_question_frame_btn;
private TextField search_tf;
private int page = 1;
private Text page_text;
private Button delete_btn;
private Button edit_btn;
private int editing_key = -1;
private DependentLayout add_question_frame;
private Button add_choice_btn;
private ListContainer OpListContainer;
List<QuestionItem> list;
QuestionItemProvider questionItemProvider;
// List OpList;
OptionItemProvider optionItemProvider;
private Button cancle_btn;
private Button add_btn;
int max_option = 5;
private Button delete_choice_btn;
private Button correct_choice_btn;
private Button score_up;
private Button score_down;
Text score_select_text;
@Override
protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
Component component=scatter.parse(ResourceTable.Layout_Question_bank,container,false);
return component;
}
//在add_question_frame中添加一个空选项
private void add_option(){
//保存已输入的选项内容到当前optionItemProvider的链表
int len = optionItemProvider.getList().size();
for (int i = 0; i< len ; i++ ){
TextField tf = (TextField) OpListContainer.getComponentAt(i).findComponentById(ResourceTable.Id_choice_input);
if (!tf.getText().equals(null))
optionItemProvider.getList().get(i).setStem(tf.getText());
}
List<OptionItem> interList = optionItemProvider.getList();
OptionItem optionItem = new OptionItem(interList.size()+"");
interList.add(optionItem);
optionItemProvider = new OptionItemProvider(interList,getFractionAbility());
OpListContainer.setItemProvider(optionItemProvider);
}
//在add_question_frame中添加指定选项
private void show_options(QuestionItem questionItem){
// OpList = questionItem.getOpList();
System.out.println(questionItem.getOpList().get(0).isAnswer());
optionItemProvider = new OptionItemProvider(questionItem.getOpList(),getFractionAbility());
OpListContainer.setItemProvider(optionItemProvider);
}
//清空add_question_frame中的所有选项
private void clear_option(){
optionItemProvider.getList().clear();
OpListContainer.setItemProvider(optionItemProvider);
}
//清空题干输入框
private void clear_stem_input(){
TextField stem_input = (TextField)
getFractionAbility().findComponentById(ResourceTable.Id_stem_input);
stem_input.setText("");
}
//显示添加习题界面
private void show_add_question_frame(){
editing_key = -1;
clear_option();
score_select_text.setText("1.0");
clear_stem_input();
Text title_text = (Text)
getFractionAbility().findComponentById(ResourceTable.Id_title_text);
title_text.setText("添加习题");
Button question_bank_add = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_question_bank_add);
question_bank_add.setText("添加");
add_question_frame.setVisibility(0);
}
//显示编辑习题界面
private void show_edit_question_frame(int key){
editing_key = key;
String stem = list.get(key).getStem();
TextField stem_input = (TextField)
getFractionAbility().findComponentById(ResourceTable.Id_stem_input);
stem_input.setText(stem);
show_options(list.get(key));
Text score = (Text)
getFractionAbility().findComponentById(ResourceTable.Id_score_select_text);
score.setText(list.get(key).getScore());
Text title_text = (Text)
getFractionAbility().findComponentById(ResourceTable.Id_title_text);
title_text.setText("编辑习题");
Button question_bank_add = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_question_bank_add);
question_bank_add.setText("保存");
add_question_frame.setVisibility(0);
}
//关闭添加习题界面
private void close_add_question_frame(){
add_question_frame.setVisibility(1);
}
@Override
protected void onStart(Intent intent) {
super.onStart(intent);
listContainer = (ListContainer)
getFractionAbility().findComponentById(ResourceTable.Id_list_question);
list = getData(page);
questionItemProvider = new QuestionItemProvider(getPageData(page), getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
add_question_frame = (DependentLayout)
getFractionAbility().findComponentById(ResourceTable.Id_add_question_frame);
cancle_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_qusetion_bank_cancle);
cancle_btn.setClickedListener(lis->{
close_add_question_frame();
});
add_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_question_bank_add);
add_btn.setClickedListener(lis->{
TextField stem_input = (TextField)
getFractionAbility().findComponentById(ResourceTable.Id_stem_input);
String stem = stem_input.getText();
if(stem.equals(""))
return;
//保存已输入的选项内容到当前optionItemProvider的链表
int len = optionItemProvider.getList().size();
for (int i = 0; i< len ; i++ ){
TextField tf = (TextField) OpListContainer.getComponentAt(i).findComponentById(ResourceTable.Id_choice_input);
if (!tf.getText().equals(null))
optionItemProvider.getList().get(i).setStem(tf.getText());
}
if (editing_key == -1){
//添加新题目
QuestionItem questionItem = new QuestionItem(stem,"testId");
questionItem.setOpList(optionItemProvider.getList());
Text score = (Text)
getFractionAbility().findComponentById(ResourceTable.Id_score_select_text);
questionItem.setScore(score.getText());
list.add(questionItem);
}else{
//修改旧题目
list.get(editing_key).setStem(stem);
list.get(editing_key).setOpList(optionItemProvider.getList());
Text score = (Text)
getFractionAbility().findComponentById(ResourceTable.Id_score_select_text);
list.get(editing_key).setScore(score.getText());
}
questionItemProvider = new QuestionItemProvider(getPageData(page), getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
close_add_question_frame();
});
OpListContainer = (ListContainer)
getFractionAbility().findComponentById(ResourceTable.Id_list_choice);
add_choice_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_add_choice_btn);
add_choice_btn.setClickedListener(lis->{
if ( optionItemProvider.getList().size() >= max_option)
return;
add_option();
});
delete_choice_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_delete_choice_btn);
delete_choice_btn.setClickedListener(lis->{
int len = optionItemProvider.getList().size();
int count = 0;
//保存已输入的选项内容到当前optionItemProvider的链表
for (int i = 0; i< len ; i++ ){
TextField tf = (TextField) OpListContainer.getComponentAt(i).findComponentById(ResourceTable.Id_choice_input);
if (!tf.getText().equals(null))
optionItemProvider.getList().get(i).setStem(tf.getText());
}
//从optionItemProvider的链表里删除选定的节点
for (int i = 0; i< len ; i++ ){
Checkbox cb = (Checkbox) OpListContainer.getComponentAt(i).findComponentById(ResourceTable.Id_check);
if (cb.isChecked()){
optionItemProvider.getList().remove(i-count);
count++;
}
}
//修改optionItemProvider的链表中对象的Sign:1234 删除2 变为134 修改为123
len = optionItemProvider.getList().size();
for (int i = 0; i< len ; i++ ){
optionItemProvider.getList().get(i).setSign(i+"");
}
OpListContainer.setItemProvider(optionItemProvider);
});
correct_choice_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_correct_choice_btn);
correct_choice_btn.setClickedListener(lis->{
int len = optionItemProvider.getList().size();
//若已选中,则修改链表OpList中相应optionItem的isAnswer属性
for (int i = 0; i< len ; i++ ){
Checkbox cb = (Checkbox) OpListContainer.getComponentAt(i).findComponentById(ResourceTable.Id_check);
if (cb.isChecked()){
if (optionItemProvider.getList().get(i).isAnswer())
optionItemProvider.getList().get(i).setAnswer(false);
else
optionItemProvider.getList().get(i).setAnswer(true);
}
}
OpListContainer.setItemProvider(optionItemProvider);
});
//升降分值
score_select_text = (Text)getFractionAbility().findComponentById(ResourceTable.Id_score_select_text);
score_up = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_score_up);
score_up.setClickedListener(lis->{
if (Float.parseFloat(score_select_text.getText())>=10)
return;
score_select_text.setText(Float.parseFloat(score_select_text.getText())+0.5+"");
});
score_down = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_score_down);
score_down.setClickedListener(lis->{
if (Float.parseFloat(score_select_text.getText())<=0.5)
return;
score_select_text.setText(Float.parseFloat(score_select_text.getText())-0.5+"");
});
show_add_question_frame_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_btn_add_question);
show_add_question_frame_btn.setClickedListener(lis->{
//显示添加习题界面
show_add_question_frame();
});
return_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_btn_return);
return_btn.setClickedListener(lis->{
questionItemProvider = new QuestionItemProvider(getPageData(page), getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
});
search_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_btn_search);
search_tf = (TextField)
getFractionAbility().findComponentById(ResourceTable.Id_search);
search_btn.setClickedListener(lis->{
String nameOrId = search_tf.getText();
ArrayList<QuestionItem> search_result = new ArrayList<>();
for (int i=0;i<list.size();i++){
QuestionItem questionItem = list.get(i);
if (questionItem.getId().equals(nameOrId)||questionItem.getStem().equals(nameOrId)){
search_result.add(questionItem);
}
}
questionItemProvider = new QuestionItemProvider(search_result, getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
});
delete_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_question_delete);
delete_btn.setClickedListener(lis->{
int len = (Math.min(list.size(),page*14) - (page-1)*14);
int count = 0;
for (int i = 0; i< len ; i++ ){
Checkbox cb = (Checkbox) listContainer.getComponentAt(i).findComponentById(ResourceTable.Id_item_name);
if (cb.isChecked()){
list.remove((page-1)*14 + (i-count));
count++;
}
}
questionItemProvider = new QuestionItemProvider(getPageData(page), getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
});
edit_btn = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_question_edit);
edit_btn.setClickedListener(lis->{
int len = (Math.min(list.size(),page*14) - (page-1)*14);
int count = 0;
int key = -1;
for (int i = 0; i< len ; i++ ){
Checkbox cb = (Checkbox) listContainer.getComponentAt(i).findComponentById(ResourceTable.Id_item_name);
if (cb.isChecked()){
key = i + (page-1)*14;
count++;
}
}
if (count!=1)
//一次只能编辑一个
return;
show_edit_question_frame(key);
});
page_text = (Text)
getFractionAbility().findComponentById(ResourceTable.Id_page);
page_text.setText(""+page);
aft = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_aft);
aft.setClickedListener(lis->{
if ((page)*14 >= list.size())
return;
questionItemProvider = new QuestionItemProvider(getPageData(++page), getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
page_text.setText(""+page);
});
pre = (Button)
getFractionAbility().findComponentById(ResourceTable.Id_pre);
pre.setClickedListener(lis->{
if (page<=1)
return;
questionItemProvider = new QuestionItemProvider(getPageData(--page), getFractionAbility());
listContainer.setItemProvider(questionItemProvider);
page_text.setText(""+page);
});
}
//从后端数据库获得所有问题信息,保存到list
private ArrayList<QuestionItem> getData(int page) {
ArrayList<QuestionItem> list = new ArrayList<>();
ArrayList<OptionItem> OpList = new ArrayList<>();
OpList.add(new OptionItem("0"));
for (int i = 1; i <= 45; i++) {
list.add(new QuestionItem("题干"+i,"id"+i, OpList,"1"));
}
return list;
}
//从list获取一页的问题信息,不连接后端
private ArrayList<QuestionItem> getPageData(int page) {
ArrayList<QuestionItem> list2 = new ArrayList<>();
for (int i = (page-1)*14; i < Math.min(list.size(),page*14); i++) {
list2.add(list.get(i));
}
return list2;
}
}
代码如下(示例):
package com.chinasofti.smartclassroomtv.data;
import com.chinasofti.smartclassroomtv.ResourceTable;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.agp.components.*;
import java.util.List;
public class QuestionItemProvider extends BaseItemProvider {
private List<QuestionItem> list;
private FractionAbility slice;
public QuestionItemProvider(List<QuestionItem> list, FractionAbility slice) {
this.list = list;
this.slice = slice;
}
@Override
public int getCount() {
return list == null ? 0 : list.size();
}
@Override
public Object getItem(int position) {
if (list != null && position >= 0 && position < list.size()){
return list.get(position);
}
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Component getComponent(int position, Component convertComponent, ComponentContainer componentContainer) {
final Component cpt;
if (convertComponent == null) {
cpt = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_item_question, null, false);
} else {
cpt = convertComponent;
}
QuestionItem questionItem = list.get(position);
Checkbox cb = (Checkbox) cpt.findComponentById(ResourceTable.Id_item_name);
cb.setText(questionItem.getStem());
Text text2 = (Text) cpt.findComponentById(ResourceTable.Id_item_id);
text2.setText(questionItem.getId());
Button btn = (Button) cpt.findComponentById(ResourceTable.Id_item_oprate);
btn.setText("...");
return cpt;
}
}
代码如下(示例):
package com.chinasofti.smartclassroomtv.data;
import ohos.agp.render.Region;
import java.util.ArrayList;
import java.util.List;
public class QuestionItem {
private String stem;
private String Id;
private List<OptionItem> OpList;
private String score;
public QuestionItem(String stem, String Id) {
this.stem = stem;
this.Id = Id;
}
public QuestionItem(String stem, String Id, List<OptionItem> OpList, String score) {
this.stem = stem;
this.Id = Id;
this.OpList = OpList;
this.score = score;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
public List<OptionItem> getOpList() {
List<OptionItem> list = new ArrayList<>();
for (int i = 0; i< OpList.size(); i++){
OptionItem optionItem = new OptionItem();
optionItem.setAnswer(OpList.get(i).isAnswer());
optionItem.setStem(OpList.get(i).getStem());
optionItem.setSign(OpList.get(i).getSign());
list.add(optionItem);
}
return list;
}
public void setOpList(List<OptionItem> opList) {
OpList = opList;
}
public String getStem() {
return stem;
}
public void setStem(String stem) {
this.stem = stem;
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
}
代码如下:
<com.chinasofti.smartclassroomtv.component.MyDependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical"
ohos:background_element="yellow"
>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical"
ohos:background_element="yellow">
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="match_content"
ohos:orientation="horizontal"
ohos:background_element="black"
ohos:margin="5vp">
<TextField
ohos:id="$+id:search"
ohos:height="30vp"
ohos:width="0vp"
ohos:background_element="$graphic:capsule_button_element"
ohos:layout_alignment="top|left"
ohos:hint="输入题干或id"
ohos:text_color="black"
ohos:text_font="HwChinese-medium"
ohos:text_alignment="vertical_center|left"
ohos:padding="5vp"
ohos:top_margin="10vp"
ohos:bottom_margin="10vp"
ohos:left_margin="10vp"
ohos:text_size="10vp"
ohos:weight="4"/>
<Button
ohos:width="0vp"
ohos:height="30vp"
ohos:background_element="$graphic:add_student_button"
ohos:text="搜索"
ohos:padding="5vp"
ohos:id="$+id:btn_search"
ohos:text_size="10vp"
ohos:left_margin="5vp"
ohos:top_margin="10vp"
ohos:text_color="black"
ohos:weight="0.5"/>
<Button
ohos:width="0vp"
ohos:height="30vp"
ohos:background_element="$graphic:add_student_button"
ohos:text="返回"
ohos:padding="5vp"
ohos:id="$+id:btn_return"
ohos:text_size="10vp"
ohos:left_margin="5vp"
ohos:top_margin="10vp"
ohos:text_color="black"
ohos:weight="0.5"/>
<Button
ohos:width="0vp"
ohos:height="30vp"
ohos:background_element="$graphic:add_student_button"
ohos:text="批量导入题目"
ohos:padding="5vp"
ohos:id="$+id:btn_batch_import_student"
ohos:text_size="10vp"
ohos:left_margin="250vp"
ohos:top_margin="10vp"
ohos:text_color="black"
ohos:weight="1"/>
<Button
ohos:width="0vp"
ohos:height="30vp"
ohos:background_element="$graphic:add_student_button"
ohos:text="添加题目"
ohos:padding="5vp"
ohos:id="$+id:btn_add_question"
ohos:text_size="10vp"
ohos:left_margin="50vp"
ohos:top_margin="10vp"
ohos:text_color="black"
ohos:weight="1"/>
DirectionalLayout>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="350vp"
ohos:orientation="vertical"
ohos:background_element="red"
ohos:left_margin="5vp"
ohos:right_margin="5vp">
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:align_parent_top="true"
ohos:text="题目(数量)"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:title"
ohos:text_color="black"
ohos:left_margin="10vp"
ohos:top_margin="10vp"
ohos:bottom_margin="10vp"/>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:background_element="blue"
ohos:orientation="horizontal">
<Checkbox
ohos:id="$+id:item_name"
ohos:height="match_content"
ohos:weight="1"
ohos:width="0vp"
ohos:text="题干"
ohos:left_margin="16vp"
ohos:text_size="10fp" />
<Text
ohos:id="$+id:item_id"
ohos:height="match_content"
ohos:weight="1"
ohos:width="0vp"
ohos:padding="4vp"
ohos:text="Id"
ohos:text_size="10fp"
ohos:left_margin="10vp"
ohos:text_alignment="center"/>
<Text
ohos:id="$+id:item_oprate"
ohos:height="match_content"
ohos:weight="1"
ohos:width="0vp"
ohos:padding="4vp"
ohos:text="操作"
ohos:left_margin="10vp"
ohos:text_size="10fp"
ohos:text_alignment="center"/>
DirectionalLayout>
<ListContainer
ohos:width="match_parent"
ohos:height="match_content"
ohos:background_element="#FFFFFFFF"
ohos:id="$+id:list_question"
>
ListContainer>
DirectionalLayout>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:background_element="#FFF700FF"
ohos:left_margin="5vp"
ohos:right_margin="5vp"
ohos:id="$+id:bottom">
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="#FF000000"
ohos:orientation="horizontal"
ohos:margin="10vp"
ohos:layout_alignment="horizontal_center">
<Button
ohos:id="$+id:pre"
ohos:height="match_parent"
ohos:width="50vp"
ohos:text="前"
ohos:text_size="10vp"
ohos:background_element="$graphic:add_student_button"
ohos:text_alignment="center"/>
<Text
ohos:id="$+id:page"
ohos:height="match_parent"
ohos:width="50vp"
ohos:text="page"
ohos:text_size="10vp"
ohos:background_element="$graphic:add_student_button"
ohos:text_alignment="center"
ohos:left_margin="10vp"
ohos:right_margin="10vp"/>
<Button
ohos:id="$+id:aft"
ohos:height="match_parent"
ohos:width="50vp"
ohos:text="后"
ohos:text_size="10vp"
ohos:background_element="$graphic:add_student_button"
ohos:text_alignment="center"/>
DirectionalLayout>
DirectionalLayout>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:background_element="#FFC300FF"
ohos:left_margin="5vp"
ohos:right_margin="5vp"
ohos:id="$+id:delete_bottom">
<Button
ohos:id="$+id:question_delete"
ohos:height="match_content"
ohos:width="50vp"
ohos:text="删除"
ohos:text_size="10vp"
ohos:background_element="$graphic:add_student_button"
ohos:text_alignment="center"
ohos:margin="5vp"/>
<Button
ohos:id="$+id:question_edit"
ohos:height="match_content"
ohos:width="50vp"
ohos:text="编辑"
ohos:text_size="10vp"
ohos:background_element="$graphic:add_student_button"
ohos:text_alignment="center"
ohos:right_of="$id:question_delete"
ohos:margin="5vp"/>
DependentLayout>
DirectionalLayout>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="415vp"
ohos:width="200vp"
ohos:background_element="#FFFFD500"
ohos:vertical_center="true"
ohos:horizontal_center="true"
ohos:left_margin="5vp"
ohos:right_margin="5vp"
ohos:visibility="invisible"
ohos:id="$+id:add_question_frame">
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:align_parent_top="true"
ohos:align_parent_left="true"
ohos:text="添加习题"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:title_text"
ohos:text_color="black"
ohos:left_margin="10vp"
ohos:top_margin="10vp"
ohos:bottom_margin="10vp"/>
<Button
ohos:width="match_content"
ohos:height="match_content"
ohos:background_element="$graphic:add_student_button"
ohos:align_parent_top="true"
ohos:align_parent_right="true"
ohos:text="取消"
ohos:padding="5vp"
ohos:id="$+id:qusetion_bank_cancle"
ohos:text_size="10vp"
ohos:margin="5vp"
ohos:text_color="black"/>
<Button
ohos:width="match_content"
ohos:height="match_content"
ohos:background_element="$graphic:add_student_button"
ohos:align_parent_top="true"
ohos:text="添加"
ohos:padding="5vp"
ohos:id="$+id:question_bank_add"
ohos:text_size="10vp"
ohos:margin="5vp"
ohos:left_of="$id:qusetion_bank_cancle"
ohos:text_color="black"/>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:below="$id:title_text"
ohos:id="$+id:kind_layout"
ohos:background_element="#FF00FFEA"
>
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:align_parent_left="true"
ohos:vertical_center="true"
ohos:text="题型"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:kind_text"
ohos:text_color="black"
ohos:margin="10vp"/>
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:right_of="$id:kind_text"
ohos:vertical_center="true"
ohos:text="单选题"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:single_choice_text"
ohos:text_color="black"
ohos:margin="10vp"/>
DependentLayout>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:below="$id:kind_layout"
ohos:id="$+id:stem_layout"
ohos:background_element="#FFFF00AA"
>
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:align_parent_left="true"
ohos:vertical_center="true"
ohos:text="题干"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:stem_text"
ohos:text_color="black"
ohos:margin="10vp"/>
<TextField
ohos:id="$+id:stem_input"
ohos:width="140vp"
ohos:height="match_content"
ohos:background_element="$graphic:capsule_button_element"
ohos:right_of="$id:stem_text"
ohos:hint="输入题干"
ohos:text_color="black"
ohos:text_font="HwChinese-medium"
ohos:text_alignment="vertical_center|left"
ohos:padding="2vp"
ohos:margin="10vp"/>
DependentLayout>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:below="$id:stem_layout"
ohos:id="$+id:choice_layout"
ohos:background_element="#FF00FFEA"
>
<ListContainer
ohos:width="match_parent"
ohos:height="match_content"
ohos:background_element="#FFFFFFFF"
ohos:id="$+id:list_choice"
>
ListContainer>
DependentLayout>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:below="$id:choice_layout"
ohos:id="$+id:add_choice_layout"
ohos:background_element="#FF0090FF"
>
<Button
ohos:width="60vp"
ohos:height="match_content"
ohos:background_element="$graphic:add_student_button"
ohos:text="新增选项"
ohos:id="$+id:add_choice_btn"
ohos:text_size="10vp"
ohos:vertical_center="true"
ohos:align_parent_left="true"
ohos:margin="5vp"
ohos:text_color="black"/>
<Button
ohos:width="60vp"
ohos:height="match_content"
ohos:background_element="$graphic:add_student_button"
ohos:text="删除选项"
ohos:id="$+id:delete_choice_btn"
ohos:text_size="10vp"
ohos:vertical_center="true"
ohos:horizontal_center="true"
ohos:margin="5vp"
ohos:text_color="black"/>
<Button
ohos:width="60vp"
ohos:height="match_content"
ohos:background_element="$graphic:add_student_button"
ohos:text="设置答案"
ohos:id="$+id:correct_choice_btn"
ohos:text_size="10vp"
ohos:vertical_center="true"
ohos:align_parent_right="true"
ohos:margin="5vp"
ohos:text_color="black"/>
DependentLayout>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:id="$+id:score_layout"
ohos:align_parent_bottom="true"
ohos:background_element="#FFFF00B7"
>
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:align_parent_left="true"
ohos:vertical_center="true"
ohos:text="本题分值"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:score_text"
ohos:text_color="black"
ohos:margin="10vp"/>
<Text
ohos:width="50vp"
ohos:height="match_content"
ohos:right_of="$id:score_text"
ohos:vertical_center="true"
ohos:text="1.0"
ohos:text_alignment="center"
ohos:text_size="10vp"
ohos:id="$+id:score_select_text"
ohos:text_color="black"
ohos:background_element="$graphic:add_student_button"
ohos:margin="10vp"/>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_content"
ohos:vertical_center="true"
ohos:id="$+id:score_select_button_layout"
ohos:right_of="$id:score_select_text"
ohos:background_element="#FFD000FF"
>
<Button
ohos:width="match_content"
ohos:height="match_content"
ohos:background_element="#FFD000FF"
ohos:text="up"
ohos:id="$+id:score_up"
ohos:text_size="10vp"
ohos:horizontal_center="true"
ohos:text_color="black"/>
<Button
ohos:width="match_content"
ohos:height="match_content"
ohos:background_element="#FFFF0000"
ohos:below="$id:score_up"
ohos:text="down"
ohos:id="$+id:score_down"
ohos:text_size="10vp"
ohos:text_color="black"/>
DependentLayout>
DependentLayout>
DependentLayout>
com.chinasofti.smartclassroomtv.component.MyDependentLayout>
代码如下:
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_parent"
ohos:orientation="horizontal"
ohos:background_element="#FF00FF04">
<Checkbox
ohos:id="$+id:item_name"
ohos:height="match_content"
ohos:weight="1"
ohos:width="0vp"
ohos:text="Name"
ohos:left_margin="16vp"
ohos:text_size="10fp" />
<Text
ohos:id="$+id:item_id"
ohos:height="match_content"
ohos:weight="1"
ohos:width="0vp"
ohos:padding="4vp"
ohos:text="Id"
ohos:text_size="10fp"
ohos:left_margin="10vp"
ohos:text_alignment="center"/>
<Button
ohos:id="$+id:item_oprate"
ohos:height="match_content"
ohos:weight="1"
ohos:width="0vp"
ohos:padding="4vp"
ohos:text="Op"
ohos:left_margin="10vp"
ohos:text_size="10fp"
ohos:text_alignment="center"/>
DirectionalLayout>