현재 Android 앱을 개발 중입니다. 멋진 레이아웃을 만들고 싶습니다.Android의 레이아웃과 같은 양면 주사위
동그라미는 당연히 동일한 크기의 것입니다 : 내가 달성하기 위해 노력하고있어
다음과 같은 레이아웃입니다. 게다가 단추 나 이미지 뷰일 필요가 있기 때문에 클릭 할 수 있어야합니다.
이런 종류의 레이아웃을 달성하는 최선의 방법은 무엇입니까?
현재 Android 앱을 개발 중입니다. 멋진 레이아웃을 만들고 싶습니다.Android의 레이아웃과 같은 양면 주사위
동그라미는 당연히 동일한 크기의 것입니다 : 내가 달성하기 위해 노력하고있어
다음과 같은 레이아웃입니다. 게다가 단추 나 이미지 뷰일 필요가 있기 때문에 클릭 할 수 있어야합니다.
이런 종류의 레이아웃을 달성하는 최선의 방법은 무엇입니까?
이 시도 ..
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
</LinearLayout>
이것은 실제로 아주 좋게 보인다. Michael Z.가 작성한 코멘트에 가장 가까운이 대답을 받아 들일 것입니다 (실제 해결책이됩니다). – jHogen
@jHogen은 받아 주셔서 감사합니다. Sean O'Toole도 좋은 대답을했습니다. – TheFlash
그래, 둘 다 당신의 구체적인 필요에 따라 괜찮은 솔루션인데, RelativeLayout은 점들이 정확히 어디에 표시되는지 더 잘 제어 할 수있게 해줍니다.하지만 일반적으로 가중치가있는 LinearLayout은 다른 화면에서 확장하는 것이 좋습니다. 어느 쪽이든 –
LinearLayout 또는 RelativeLayout의 중첩을 사용하십시오. 이미지를 버튼으로 사용하려면 ImageView를 사용하고 xml에 해당하는 ID로 각 이미지를 표시하여 활동에 사용할 수 있도록하십시오.
RelativeLayout
을 사용하고 각 점이 다른 점과 관련되어 있어야한다고 말할 수 있습니다.
LinearLayout
을 사용하여 3 개의 '행'버튼을 만들 수 있습니다. 상단 및 하단 행에는 '점'두 개와 가운데 하나에 가운데 점이 포함됩니다.
다음과 같이 보일 것 레이아웃 :
그리고 코드는 다음과 같이 될 것이다 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/dot"
android:background="@android:color/transparent"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/dot2"
android:background="@android:color/transparent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/dot3"
android:background="@android:color/transparent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/dot4"
android:background="@android:color/transparent"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/dot5"
android:background="@android:color/transparent"/>
</LinearLayout>
</LinearLayout>
이것은 레이아웃을 달성하는 쉬운 방법처럼 보입니다. 비록 각 모서리와 화면 중앙에 버튼을 배치 할 수 있기 때문에 상대적 레이아웃이 더 쉽다고 생각합니다. 그러나 다른 사람들에게 더 좋은 해결책이 될 수있는 좋은 대답입니다. – jHogen
네, 당신의 특정 요구에 따라, RelativeLayouts 좀 더 미세한 세부 사항을 제어 할 수 있지만, 일반적으로 새로운 레이아웃을 지정할 필요없이 다른 화면을 통해 스케일링 할 때 좋네요 LinearLayouts 더 좋게 찾을 수 있습니다. –
RelativeLayout의 사용 및 ImageViews/ImageButtons. –
충분히 쉽게 들리는 알맞은, 그것에 들여다 볼 것입니다! – jHogen
'RelativeLayout','LinearLayout' 또는'GridLayout'가 모두 수행해야합니다. 후자의 두 가지 방법은 다른 화면 크기/비율에 대해 동적으로 배율을 조정할 레이아웃이 필요한 경우 더 적합 할 수 있습니다 (겹쳐진 요소가 필요없고 원이 어느 정도 균등하게 분산되어있는 경우). –