【问题标题】:How to display seats image in android like below picture?如何在 android 中显示座位图像,如下图所示?
【发布时间】:2017-01-03 10:08:56
【问题描述】:

嗨,我想在我的应用程序中显示这样的座位图像。我是 android 新手。我不知道应该使用什么布局和方法。目前我正在计划列表视图,但我不确定什么方法和我应该使用布局。请任何人建议

【问题讨论】:

  • 使用 ImageView 显示 1 个座位的图像。为 1 行创建一个布局,其中将包含 4 个此图像。在 ListView 或 RecyclerView 中使用该布局。准备不同颜色版本的座位图像以显示空座位或占用座位
  • 你可以按照@Marat的建议去做,如果你没有得到他的建议,那么你必须先学习一下android
  • 我会使用 GridView。对我来说似乎更“自然”。

标签: android android-layout android-studio


【解决方案1】:

您应该使用桌子布局或线性布局来安排座位,并且在按钮中使用图像,其中使用的按钮是图像按钮。您应该根据手机,平板电脑的分辨率在每个drawable中插入图片。

【讨论】:

    【解决方案2】:

    您应该从Linearlayout 开始,它以特定方向显示其子视图。

    <Linearlayout orientation="vertical"> 
     <TextView> </TextView>
     <TextView> </TextView>
    </Linearlayout>
    

    第二个文本视图将首先显示在下方!

    <Linearlayout orientation="horizontal"> 
         <TextView> </TextView>
         <TextView> </TextView>
    </Linearlayout>
    

    第二个文本视图将首先显示!

    最常用的viewGroup是RelativeLayout,其中views是相对放置的!它用于开发复杂的设计,非常强大!

    【讨论】:

      【解决方案3】:

      动态添加这样的布局

      LinearLayout linearLayout = new LinearLayout(this);
              ArrayList<Seat> seats = new ArrayList<>();
      
              for (int i = 0; i < seats.size(); i++) {
                  ImageView imageView = new ImageView(this);
      
                  if(seats.get(i).getStatus() == AVAILABLE) {
                      imageView.setImageResource(R.drawable.available);
                  } else if(seats.get(i).getStatus() == UNAVAILABLE) {
                      imageView.setImageResource(R.drawable.unavailable);
                  } else if(seats.get(i).getStatus() == SELECTED) {
                      imageView.setImageResource(R.drawable.selected);
                  }
              }
      
              mylistview.addView(linearLayout);
      

      添加 Seat.java

      public class Seat {
              private int id = 0;
              private String name="";
              private int status=0;
      
              public int getStatus() {
                  return status;
              }
      
              public void setStatus(int status) {
                  this.status = status;
              }
      
              public int getId() {
                  return id;
              }
      
              public void setId(int id) {
                  this.id = id;
              }
      
              public String getName() {
                  return name;
              }
      
              public void setName(String name) {
                  this.name = name;
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-23
        • 2021-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-16
        • 2015-10-21
        • 2012-06-06
        相关资源
        最近更新 更多