1

아래 그림에서와 같이 아이콘이있는 육각형보기 메뉴를 만들려고합니다. imageview에 대한 github에서 library을 사용하려고했지만 내 요구 사항에 맞지 않아 특정 육각형 영역에서 클릭 이벤트가있는 육각형 뷰가 필요합니다. 라이브러리는 단일 이미지 대상에 대해 육각형보기를 제공하지만 육각형 메뉴의 경우 육각형 출력을 제공하지 못합니다 (즉, 레이아웃에서 제대로 정렬 할 수 없음).android에서 육각형보기 메뉴를 만드는 방법

레이아웃 개선이나 코드 개선 제안에 도움을주십시오. 미리 감사드립니다.

enter image description here

+1

이보기는 캔버스를 사용하여 그려 지거나 drawable의 이미지를 사용하여 특정 xy 좌표의 캔버스에 설정할 수 있습니다. 분명히 수학적 계산이 필요합니다. –

+0

Thanks Rahul gupta. 만들 수있는 다른 방법이 있습니까 ?? 드로잉 캔버스는 레이아웃에서 드로어 블과 위치를 정렬하는 데 많은 시간을 소비한다고 생각합니다. – Chandru

답변

1

난 유, ImageViews을 사용하고있는 LinearLayout 마이너스 마진을 적용 필요한 레이아웃을 생성하기 위해 노력했다.

이상적인 사용 방법인지 잘 모르겠지만 캔버스에 가고 싶지 않다면 사용해 볼 수 있습니다.

아래의 예를 통해 이동하시기 바랍니다 ...

<LinearLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible"/> 

     </LinearLayout> 



    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="-25dp"> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:layout_marginLeft="12.5dp"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible" 
/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:layout_marginLeft="-25dp"/> 

    </LinearLayout> 




    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="-25dp"> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible"/> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="-25dp"> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:layout_marginLeft="12.5dp"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible" 
      /> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:layout_marginLeft="-25dp"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="-25dp"> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa"/> 
     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/hexa" 
      android:visibility="invisible"/> 

    </LinearLayout> 
</LinearLayout> 

여기 drawable/hexa는 단일 흰색 육각형 PNG 이미지입니다.

+0

감사합니다 nDroidDev. 이것이 내가 필요한 것입니다. 하지만 모서리 가장자리를 만지면 문제가 발생할 수 있습니다. 클릭 이벤트가 접힐 수 있습니다. 그걸 처리 할 솔루션이 있습니까 ?? – Chandru

+0

도움이된다면 .. click 이벤트에 대해서 .. 이미지가 보이지 않기 때문에 다른 사람들의 클릭 리스너에 영향을주지 않아야합니다. 보이지 않는 이미지에 대해서는 'clickable = false'를 설정하고 표시되는 이미지에 대해서는'true '로 설정 한 다음 시도하십시오 – iMDroid

1

육각보기의 아래에 첨부 된 코드 ... 희망이 도움이. 당신의 확신을위한 버튼 이미지 변경

<FrameLayout 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" 
android:gravity="center" 
tools:context="com.example.me.testapplication.Buttons"> 


<LinearLayout 
    android:id="@+id/ll1" 
    android:layout_width="211dp" 
    android:layout_height="fill_parent" 
    android:gravity="center" 
    android:orientation="vertical" 

    > 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:background="@drawable/cell"></Button> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/cell" /> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/ll3" 
    android:layout_width="216dp" 
    android:layout_height="fill_parent" 
    android:layout_alignParentTop="true" 
    android:layout_gravity="right|top" 

    android:layout_toEndOf="@+id/ll2" 
    android:gravity="center" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:background="@drawable/cell"></Button> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/cell" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/ll2" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentTop="true" 
    android:layout_gravity="center_horizontal|top" 

    android:layout_toEndOf="@+id/ll1" 
    android:gravity="center" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/cell" 
     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/cell" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/cell" /> 
</LinearLayout> 


</FrameLayout> 
관련 문제