Java 安卓:在大图的顶部显示多个较小的图像,在小图的内部显示文本
我正在开发一个Android应用程序,其中有一个名为Section的容器,其中可以包含Note对象。用例是用户可以在一个部分中放置多个注释并组织它们。当前,我要用背景图像显示从服务器检索到的节名称 现在我的问题是如何在分区内显示从服务器接收的多个注释 我知道这可以通过FrameLayout实现,但我的问题是动态注释计数 请注意,根据用户的不同,笔记的数量可能会有所不同 以下是当前各部分外观的原始屏幕截图: 现在,当您添加注释时,理想情况下应如下所示: 节中的每个块都包含注释对象。为了显示它的内容,我想显示一个注释块类型的图像和几个单词 注释的内容。 目前,我有代码从服务器检索注释,可以显示部分,但我真的不知道如何继续,因为注释可以是动态的。这是到目前为止我的代码Java 安卓:在大图的顶部显示多个较小的图像,在小图的内部显示文本,java,android,image,android-framelayout,Java,Android,Image,Android Framelayout,我正在开发一个Android应用程序,其中有一个名为Section的容器,其中可以包含Note对象。用例是用户可以在一个部分中放置多个注释并组织它们。当前,我要用背景图像显示从服务器检索到的节名称 现在我的问题是如何在分区内显示从服务器接收的多个注释 我知道这可以通过FrameLayout实现,但我的问题是动态注释计数 请注意,根据用户的不同,笔记的数量可能会有所不同 以下是当前各部分外观的原始屏幕截图: 现在,当您添加注释时,理想情况下应如下所示: 节中的每个块都包含注释对象。为了显示它的
public class GroupSectionActivity extends Activity {
private SectionServiceImpl sectionService = new SectionServiceImpl();
private NoteServiceImpl noteService = new NoteServiceImpl();
private static volatile List<RestSection> restSectionList = new ArrayList<>();
private static volatile List<RestNote> restNoteList = new ArrayList<>();
private static volatile Long groupAccountId;
private static volatile Integer canvasid;
ListView listView;
SectionLazyAdapter sectionLazyAdapter;
static final String msectionname = "msectionname";
static final String msectionid = "msectionid";
Button addSectionButton;
EditText sectionName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sectionlayout);
Bundle extras = getIntent().getExtras();
if (extras != null) {
groupAccountId = extras.getLong("groupid");
canvasid = extras.getInt("canvasid");
}
restSectionList = this.sectionService.getSectionByCanvas(canvasid);
ArrayList<HashMap<String, String>> restSectionArrayList = new ArrayList<HashMap<String, String>>();
for (RestSection restSection : restSectionList) {
HashMap<String, String> sectionDisplay = new HashMap<>();
sectionDisplay.put("msectionid", String.valueOf(restSection.getMsectionid()));
sectionDisplay.put("msectionname", restSection.getMsectionname());
restSectionArrayList.add(sectionDisplay);
}
listView = (ListView) findViewById(R.id.seclist);
sectionLazyAdapter = new SectionLazyAdapter(this, restSectionArrayList);
listView.setAdapter(sectionLazyAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int sectionId = restSectionList.get(position).getMsectionid();
Log.d("Sectionid is ", String.valueOf(sectionId));
/*Intent intent = new Intent(GroupSectionActivity.this, GroupSectionActivity.class);
intent.putExtra("groupid", groupAccountId);
intent.putExtra("sectionid", sectionId);
startActivity(intent);
finish();*/
}
});
公共类GroupSectionActivity扩展活动{
private SectionServiceImpl sectionService=新SectionServiceImpl();
private NoteServiceImpl noteService=new NoteServiceImpl();
private static volatile List restSectionList=new ArrayList();
私有静态易失性列表restNoteList=newArrayList();
私有静态可变长groupAccountId;
私有静态可变整数canvasid;
列表视图列表视图;
部分懒散适配器部分懒散适配器;
静态最终字符串msectionname=“msectionname”;
静态最终字符串msectionid=“msectionid”;
按钮addSectionButton;
编辑文本部分名称;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sectionlayout);
Bundle extras=getIntent().getExtras();
如果(附加值!=null){
groupAccountId=extras.getLong(“groupid”);
canvasid=extras.getInt(“canvasid”);
}
restSectionList=this.sectionService.getSectionByCanvas(canvasid);
ArrayList restSectionArrayList=新建ArrayList();
用于(RestSection RestSection:restSectionList){
HashMap sectionDisplay=新建HashMap();
sectionDisplay.put(“msectionid”,String.valueOf(restSection.getMsectionid());
sectionDisplay.put(“msectionname”,restcreation.getMsectionname());
restSectionArrayList.add(sectionDisplay);
}
listView=(listView)findViewById(R.id.seclist);
sectionLazyAdapter=新的sectionLazyAdapter(此,restSectionArrayList);
setAdapter(sectionLazyAdapter);
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
int sectionId=restSectionList.get(position.getMsectionid();
Log.d(“Sectionid为”,String.valueOf(Sectionid));
/*意向意向=新意向(GroupSectionActivity.this、GroupSectionActivity.class);
intent.putExtra(“groupid”,groupAccountId);
意图。额外(“部分ID”,部分ID);
星触觉(意向);
完成()*/
}
});
BaseAdapter管理这些家伙:
public class SectionLazyAdapter extends BaseAdapter{
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public SectionLazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.activity_group_section, null);
TextView sectionName = (TextView)vi.findViewById(R.id.sectionname); // title
// ImageView sectionImage=(ImageView)vi.findViewById(R.id.sectionimage); // thumb image
HashMap<String, String> sectionList = new HashMap<String, String>();
sectionList = data.get(position);
// Setting all values in listview
sectionName.setText(sectionList.get(GroupSectionActivity.msectionname));
return vi;
}
}
公共类部分LazyAdapter扩展了BaseAdapter{
私人活动;
私有数组列表数据;
专用静态充气机=空;
公共分区LazyAdapter(活动a,ArrayList d){
活动=a;
数据=d;
充气器=(LayoutInflater)activity.getSystemService(Context.LAYOUT\u充气器\u SERVICE);
}
public int getCount(){
返回data.size();
}
公共对象getItem(int位置){
返回位置;
}
公共长getItemId(int位置){
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视图vi=转换视图;
if(convertView==null)
vi=充气机。充气(R.layout.activity\u group\u section,空);
TextView sectionName=(TextView)vi.findViewById(R.id.sectionName);//标题
//ImageView sectionImage=(ImageView)vi.findViewById(R.id.sectionImage);//拇指图像
HashMap sectionList=新建HashMap();
sectionList=data.get(位置);
//在listview中设置所有值
sectionName.setText(sectionList.get(GroupSectionActivity.msectionname));
返回vi;
}
}
activity_group_section.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:id="@+id/sectionimage"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:scaleType="fitXY"
android:src="@drawable/sectionbackground"
/>
</FrameLayout>
<TextView
android:id="@+id/sectionname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView"
android:visibility="visible"
android:gravity="center"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>
sectionlayout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="{relativePackage}.${activityClass}" >
<ListView
android:id="@+id/seclist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/sectionAddButton">
</ListView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sectionAddButton"
android:layout_alignParentTop="true"
android:background="@drawable/sectionbackground"
android:text="Add Section" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sectionNameTextField"
android:layout_alignBottom="@+id/sectionAddButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@+id/sectionAddButton"
android:hint="Section Name"
android:gravity="center"
android:layout_toRightOf="@+id/sectionAddButton" />
</RelativeLayout>
我希望问题是清楚的,如果缺少什么,请告诉我。如果您想以动态方式显示注释,您应该在每个容器内实现GridView,如果您为网格内的每个注释设置了正确的边距,组件将根据您的节段进行尺寸标注 GridView适配器非常简单,工作方式与ListView适配器类似,您只需要定义列的数量,您可以在XML中或在Java代码中以编程方式进行定义
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"/>
如果要以动态方式显示注释,应在每个容器内实现GridView,如果为网格内的每个注释设置了右侧边距,则组件将对其自身进行尺寸标注以适合您的部分 GridView适配器非常简单,工作方式与ListView适配器类似,您只需要定义列的数量,您可以在XML中或在Java代码中以编程方式进行定义
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"/>
如果要显示