2013-10-01 14 views
17

Tôi muốn phát triển màn hình sau trong Android. enter image description hereBố cục Thông tư

Tôi đã sử dụng CircleLayout nhưng tôi vẫn không thể đạt được kết quả mong muốn. Xem mã và ảnh chụp màn hình sau.

<com.example.hl.CircleLayout 
     android:id="@+id/pie" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     custom:dividerWidth="5dp" 
     custom:innerCircle="@drawable/profile_pic_icon" 
     custom:innerRadius="50dp" 
     custom:layoutMode="pie" 
     custom:sliceDivider="@android:color/transparent" > 

     <RelativeLayout 
      android:id="@+id/appt_center_container" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/appt_center_bg" > 

      <TextView 
       android:id="@+id/one" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:onClick="onClick" 
       android:text="APP CENTER" 
       android:textStyle="bold" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/meds_cabinet_bg" > 

      <TextView 
       android:id="@+id/two" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:onClick="onClick" 
       android:text="MEDS CABINET" 
       android:textStyle="bold" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/check_in_bg" > 

      <TextView 
       android:id="@+id/three" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:onClick="onClick" 
       android:text="CHECK-IN" 
       android:textStyle="bold" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/my_tracker_bg" > 

      <TextView 
       android:id="@+id/four" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:onClick="onClick" 
       android:text="MY TRACKERS" 
       android:textStyle="bold" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/myaccount_bg" > 

      <TextView 
       android:id="@+id/five" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:onClick="onClick" 
       android:text="MY ACCOUNTS" 
       android:textStyle="bold" /> 
     </RelativeLayout> 
    </com.example.hl.CircleLayout> 

screenshot enter image description here

Câu hỏi: -

Có bất kỳ thư viện khác có thể giúp phát triển màn hình mong muốn?

Làm cách nào để phát triển màn hình như vậy bằng chế độ xem tùy chỉnh? Tôi có nghĩa là các bước để phát triển xem tùy chỉnh dễ dàng như thế nào?

+0

tôi có lẽ sẽ sử dụng AbsoluteLayout phản đối và thực hiện tất cả x, tính toán y của các nút khác nhau bản thân mình tương đối so với tổng kích thước có sẵn. Hãy nhớ để tái calc tất cả các vị trí trên thay đổi kích cỡ. – talkol

+2

Bạn đã kiểm tra dự án mẫu chưa? Sự khác biệt đầu tiên mà tôi thấy là tất cả các con trực tiếp của 'CircleLayout' đều có' match_parent' cho chiều cao/chiều rộng, trong khi con của bạn thì không. Đi qua nó và bắt chước ví dụ như tốt nhất bạn có thể, sau đó xem nếu nó giúp bạn gần hơn. Nhân tiện, "Có thư viện nào khác ..." không có chủ đề ở đây và câu hỏi khác của bạn quá rộng. Tôi muốn gắn bó với "Làm thế nào tôi có thể sửa chữa CircleLayout này ...". – Geobits

+0

@ becomputer06 Bạn đã giải quyết được vấn đề chưa? – SeniorJD

Trả lời

28

Tôi đã triển khai một thư viện cho bố cục hình tròn. Hiện đang được phát triển, về cơ bản đáp ứng nhu cầu tôi nghĩ. Cảm thấy tự do để ngã ba và phát triển.

https://github.com/ycagri/CircularLayout

Cuối Sửa

Bạn có thể sử dụng một cách bố trí tùy chỉnh đưa ra dưới đây. Số lượng mục, bán kính trong và bán kính ngoài được xác định trong lớp. Bạn có thể sử dụng các biến đó làm thuộc tính bố cục tùy chỉnh. Bố cục được đưa ra bên dưới vẽ biểu tượng trình khởi chạy Android ở giữa và xung quanh vòng kết nối. Tiêu đề được vẽ bên dưới các mục lựa chọn.

Ảnh chụp màn hình thuộc về thiết bị Nexus 7. Thêm lề và đệm có thể được xác định để có được kết quả tốt hơn trên các độ phân giải màn hình khác nhau.

public class CircleLayout extends View { 

private final static int TOTAL_DEGREE = 360; 
private final static int START_DEGREE = -90; 

private Paint mPaint; 
private RectF mOvalRect = null; 

private int mItemCount = 5; 
private int mSweepAngle; 

private int mInnerRadius; 
private int mOuterRadius; 
private Bitmap mCenterIcon; 
private int[] mColors = {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.CYAN}; 
private String[] mTitles = {"APPT CENTER", "MEDS CABINET", "CHECK-IN", "MY TRACKERS", "MY ACCOUNTS"}; 

public CircleLayout(Context context) { 
    this(context, null); 
} 

public CircleLayout(Context context, AttributeSet attrs) { 
    this(context, attrs, 0); 
} 

public CircleLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 
    mPaint.setStrokeWidth(2); 

    mSweepAngle = TOTAL_DEGREE/mItemCount; 

    mInnerRadius = 125; 
    mOuterRadius = 400; 

    mCenterIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); 
} 

@Override 
protected void onDraw(Canvas canvas) { 

    int width = getWidth(); 
    int height = getHeight(); 

    if (mOvalRect == null) { 
     mOvalRect = new RectF(width/2 - mOuterRadius, height/2 - mOuterRadius, width/2 + mOuterRadius, height/2 + mOuterRadius); 
    } 

    for (int i = 0; i < mItemCount; i++) { 
     int startAngle = START_DEGREE + i * mSweepAngle; 
     mPaint.setColor(mColors[i]); 
     mPaint.setStyle(Paint.Style.FILL); 
     canvas.drawArc(mOvalRect, startAngle, mSweepAngle, true, mPaint); 

     mPaint.setColor(Color.BLACK); 
     mPaint.setStyle(Paint.Style.STROKE); 
     canvas.drawArc(mOvalRect, startAngle, mSweepAngle, true, mPaint); 

     int centerX = (int) ((mOuterRadius + mInnerRadius)/2 * Math.cos(Math.toRadians(startAngle + mSweepAngle/2))); 
     int centerY = (int) ((mOuterRadius + mInnerRadius)/2 * Math.sin(Math.toRadians(startAngle + mSweepAngle/2))); 
     canvas.drawBitmap(mCenterIcon, width/2 + centerX - mCenterIcon.getWidth()/2, height/2 + centerY - mCenterIcon.getHeight()/2, null); 

     mPaint.setColor(Color.BLACK); 
     mPaint.setStyle(Paint.Style.FILL); 
     canvas.drawText(mTitles[i], width/2 + centerX - mCenterIcon.getWidth()/2, height/2 + centerY + mCenterIcon.getHeight(), mPaint); 
    } 

    mPaint.setColor(Color.WHITE); 
    mPaint.setStyle(Paint.Style.FILL); 
    canvas.drawCircle(width/2, height/2, mInnerRadius, mPaint); 
    canvas.drawBitmap(mCenterIcon, width/2 - mCenterIcon.getWidth()/2, height/2 - mCenterIcon.getHeight()/2, null); 

    super.onDraw(canvas); 
} 
} 

enter image description here

+1

Nhưng cách làm cho các mục có thể nhấp được ?? – Mohamed

+0

Bạn nên ghi đè phương thức onTouch. Bạn có thể nhận được vị trí cảm ứng và phải tính toán mục nào được chạm vào. Khi mục liên quan được chạm vào, bạn có thể chỉ cần thêm một số độ mờ cho màu. – ycagri

+0

hey @ycagri nếu tôi overirde vào sự kiện xúc động .. và sau khi tính toán xem làm thế nào tôi có thể chuyển sang trang tiếp theo ... tôi muốn bất cứ khi nào xem được nhấp .. nó nên chuyển đến trang đó – Tufan