2012-11-04 4 views
2

간단한 Android 애플리케이션을 만들고 있습니다. http://flic.kr/p/dqwmT9Android : 버튼을 텍스트 아래에 배치하고 동일한 줄에 두지 마십시오.

하지만,이 버튼은 "점수 : 0"아래에 있어야 할 : 내가 가지고있는

출력을주고있다

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="Score: " 
    tools:context=".Adder" /> 
<TextView 
    android:id="@+id/score" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="0" 
    tools:context=".Adder" /> 
<Button 
    android:id="@+id/one" 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:text="1" 
    android:textSize="20dp" /> 

<Button 
android:id="@+id/two" 
android:layout_width="50dp" 
android:layout_height="wrap_content" 
android:text="2" 
android:textSize="20dp" /> 

:

는 XML 코드 출력을주는 몇 가지 시도 : http://flic.kr/p/dqwbxD

이 문제를 해결하려면 어떻게해야합니까?

참고 : 사진을 업로드 할만큼 충분한 평판이 없기 때문에 링크를 제공했습니다.

답변

0

선형 레이아웃 대신에 상대 레이아웃을 사용하십시오.

<Button 
android:id="@+id/one" 
android:layout_width="50dp" 
android:layout_height="wrap_content" 
android:layout_below="@id/score_text" 
android:text="1" 
android:textSize="20dp" /> 

0

당신은 (그것이 LinearLayout 경우) 부모 레이아웃에

android:orientation="vertical" 

을 설정해야합니다. 부모 레이아웃이 RealativeLayout 경우 당신은 당신이 TextView 아래가 원하는 버튼에

android:below="id of the view above" 

을 설정해야합니다.

편집 (당신의 ParentLayout이 LinearLayout이기 때문에) :

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="Score: " 
     tools:context=".Adder" /> 
    <TextView 
     android:id="@+id/score" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="0" 
     tools:context=".Adder" /> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
    > 

    <Button 
     android:id="@+id/one" 
     android:layout_width="50dp" 
     android:layout_height="wrap_content" 
     android:text="1" 
     android:textSize="20dp" /> 

    <Button 
    android:id="@+id/two" 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:text="2" 
    android:textSize="20dp" /> 
    /> 

/> 
+0

감사합니다. 하지만 이제는 두 버튼이 별도의 줄에 있습니다. – user221287

+0

LinearLayout의 버튼을 감싸고 방향을 가로로 설정합니다. – Ahmad

+0

@ user169357 나는 글을 편집했습니다. – Ahmad

2

이보십시오. 사실 복사하고 붙여 넣기 만 할 수 있습니다. 속성을 변경하면 갈 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/txtScoreLabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="5dp" 
     android:layout_marginTop="5dp" 
     android:text="Score" /> 

    <TextView 
     android:id="@+id/txtScore" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/txtScoreLabel" 
     android:layout_marginLeft="5dp" 
     android:layout_toRightOf="@+id/txtScoreLabel" 
     android:text="0" /> 

    <Button 
     android:id="@+id/one" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/txtScoreLabel" 
     android:layout_below="@+id/txtScoreLabel" 
     android:text="Button One" /> 

    <Button 
     android:id="@+id/two" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/one" 
     android:layout_marginLeft="5dp" 
     android:layout_toRightOf="@+id/one" 
     android:text="Button Two" /> 

</RelativeLayout> 
1

당신은 "점수"그럼 보여줍니다 텍스트 뷰에 ID를 할당 할 RelativeLayout를 사용하려면 : 다음

<TextView 
    android:id="@+id/score_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="Score: " 
    tools:context=".Adder" /> 

당신이에 따라 버튼을 위치 지정이 있습니다

<Button 
    android:id="@+id/one" 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/score_text" 
    android:text="1" 
    android:textSize="20dp" /> 
<Button 
    android:id="@+id/one" 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/score_text" 
    android:layout_toRightOf="@id/one" 
    android:text="2" 
    android:textSize="20dp" /> 
관련 문제