나는 레이아웃을 멋지게 만드는 데 어려움을 겪고있다.GridLayout을 사용하여 계산기를 망친다
기본 사항을 이해하기 위해 간단한 계산기 앱을 만들기로 결정했습니다.
그래서, LinearLayout에 중첩 된 GridLayout을 사용하여 텍스트 필드 아래에 Button을 배치합니다.
여기 내 레이아웃 소스입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="0"
android:layout_weight="30"/>
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnCount="4"
android:rowCount="5"
android:orientation="horizontal"
android:useDefaultMargins="false"
android:layout_weight="70">
<Button
android:text="C" />
<Button
android:text="BS" />
<Button
android:text="/" />
<Button
android:text="x" />
<Button
android:text="7" />
<Button
android:text="8" />
<Button
android:text="9" />
<Button
android:text="-" />
<Button
android:text="4" />
<Button
android:text="5" />
<Button
android:text="6" />
<Button
android:text="+" />
<Button
android:text="1" />
<Button
android:text="2" />
<Button
android:text="3" />
<Button
android:layout_gravity="fill"
android:layout_rowSpan="2"
android:text="=" />
<Button
android:layout_gravity="fill"
android:layout_columnSpan="2"
android:text="0" />
<Button
android:text="." />
</GridLayout>
</LinearLayout>
이 레이아웃을 화면에 채우는 방법은 무엇입니까?
그리고 만들어 내 응용 프로그램은 빠른 답변에 대한 희망이
처럼 보이는.
[편집] 이제는 상황이 나아졌지만 새로운 질문이 생겼습니다. 지금 내 주요 활동은 내 의견으로는, 아주 좋은이
처럼 보이지만 :
- 방법은 키보드의 오른쪽에 빈 공간을 제거하려면?
- 키보드와 텍스트보기를 각각 70과 30 퍼센트의 화면과 같이 만드는 방법은 무엇입니까?
또한, 새로운 레이아웃 코드는 다음과 같습니다
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="android.calcandroid.MainActivity">
<TextView
android:background="@drawable/shape"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="0"
android:layout_above="@+id/gridLayout" />
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:columnCount="4"
android:rowCount="5"
android:orientation="horizontal"
android:useDefaultMargins="false">
<Button
android:background="@drawable/shape"
android:text="C" />
<Button
android:background="@drawable/shape"
android:text="BS" />
<Button
android:background="@drawable/shape"
android:text="/" />
<Button
android:background="@drawable/shape"
android:text="x" />
<Button
android:background="@drawable/shape"
android:text="7" />
<Button
android:background="@drawable/shape"
android:text="8" />
<Button
android:background="@drawable/shape"
android:text="9" />
<Button
android:background="@drawable/shape"
android:text="-" />
<Button
android:background="@drawable/shape"
android:text="4" />
<Button
android:background="@drawable/shape"
android:text="5" />
<Button
android:background="@drawable/shape"
android:text="6" />
<Button
android:background="@drawable/shape"
android:text="+" />
<Button
android:background="@drawable/shape"
android:text="1" />
<Button
android:background="@drawable/shape"
android:text="2" />
<Button
android:background="@drawable/shape"
android:text="3" />
<Button
android:background="@drawable/shape"
android:layout_gravity="fill_vertical"
android:layout_rowSpan="2"
android:text="=" />
<Button
android:background="@drawable/shape"
android:layout_gravity="fill_horizontal"
android:layout_columnSpan="2"
android:text="0" />
<Button
android:background="@drawable/shape"
android:text="." />
</GridLayout>
</RelativeLayout>
TableLayout을 사용해보십시오. 그럼 당신은 화면의 너비에 맞게 열을 늘릴 수 –
그리드는 그것을 할 수 없어? – likeanowl
GridView 또는 GridLayout은 계산기 앱에 적합합니다. –