2012-09-18 2 views
0

나는 하나의 이상한 종류의 문제에 직면하고있는 안드로이드 용 응용 프로그램을 만들고 있습니다. 문제는 내가 파일의 그래픽 레이아웃에서 동일한 방식으로 표시되는 화면의 중앙에 단추를 배치했는데, 에뮬레이터에서 응용 프로그램을 실행하면 단추가 오른쪽으로 더 많이 배치되고 가운데에 배치되지 않습니다. . 누구든지 문제를 지적 할 수 있습니까?런타임에 버튼 위치가 변경됩니다.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:panel="http://schemas.android.com/apk/res-auto" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#CCC" 
android:orientation="vertical" > 

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

    <org.miscwidgets.widget.Panel 
     android:id="@+id/mytopPanel" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="4dip" 
     panel:animationDuration="1000" 
     panel:closedHandle="@drawable/top_switcher_collapsed_background" 
     panel:content="@+id/mypanelContent" 
     panel:handle="@+id/mypanelHandle" 
     panel:linearFlying="true" 
     panel:openedHandle="@drawable/top_switcher_expanded_background" 
     panel:position="top" > 

     <Button 
      android:id="@+id/mypanelHandle" 
      android:layout_width="fill_parent" 
      android:layout_height="33dip" 
      android:paddingRight="50dp" /> 

     <LinearLayout 
      android:id="@+id/mypanelContent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <EditText 
       android:id="@+id/editTextUserName" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:layout_marginTop="6dp" 
       android:hint="@string/editUserName" > 
      </EditText> 

      <EditText 
       android:id="@+id/editTextPassword" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:hint="@string/editUserPwd" > 
      </EditText> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#323299" 
       android:gravity="center" 
       android:padding="4dip" 
       android:text="@string/drpDwnTxt" 
       android:textColor="#eee" 
       android:textSize="16dip" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </org.miscwidgets.widget.Panel> 

    <EditText 
     android:id="@+id/editTextNumber" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="3dp" 
     android:layout_marginTop="6dp" 
     android:hint="@string/editNumber" > 
    </EditText> 

    <EditText 
     android:id="@+id/editTextMessage" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:layout_margin="3dp" 
     android:hint="@string/editPwd" > 
    </EditText> 

    <Spinner 
     android:id="@+id/spinnerGateway" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:drawSelectorOnTop="true" 
     android:entries="@array/spinnerList" 
     android:prompt="@string/spinnerPrompt" /> 

    <Button 
     android:id="@+id/btnSend" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="3dp" 
     android:onClick="save" 
     android:text="@string/StrbtnSend" > 
    </Button> 
</LinearLayout> 

</FrameLayout> 

enter image description here

답변

0

이 새로운 레이아웃 파일이 저에게 도움이되었습니다. 하나의 작은 오류로 인해 문제가 발생했습니다.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:panel="http://schemas.android.com/apk/res-auto" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#CCC" 
android:orientation="vertical" > 

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

    <org.miscwidgets.widget.Panel 
     android:id="@+id/mytopPanel" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     panel:animationDuration="1000" 
     panel:closedHandle="@drawable/top_switcher_collapsed_background" 
     panel:content="@+id/mypanelContent" 
     panel:handle="@+id/mypanelHandle" 
     panel:linearFlying="true" 
     panel:openedHandle="@drawable/top_switcher_expanded_background" 
     panel:position="top" > 

     <Button 
      android:id="@+id/mypanelHandle" 
      android:layout_width="wrap_content" 
      android:layout_height="33dip" 
      android:layout_gravity="center_horizontal" /> 

     <LinearLayout 
      android:id="@+id/mypanelContent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <EditText 
       android:id="@+id/editTextUserName" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:layout_marginTop="6dp" 
       android:hint="@string/editUserName" > 
      </EditText> 

      <EditText 
       android:id="@+id/editTextPassword" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:hint="@string/editUserPwd" > 
      </EditText> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#323299" 
       android:gravity="center" 
       android:padding="4dip" 
       android:text="@string/drpDwnTxt" 
       android:textColor="#eee" 
       android:textSize="16dip" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </org.miscwidgets.widget.Panel> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <AutoCompleteTextView 
      android:id="@+id/mmWhoNo" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_marginTop="10dp" 
      android:layout_toLeftOf="@+id/btnContact" 
      android:hint="To: Type to search" 
      android:textSize="13sp" /> 

     <Button 
      android:id="@+id/btnContact" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_alignParentRight="true" 
      android:layout_marginTop="10dp" 
      android:background="@drawable/contacts_icon" 
      android:textSize="18dp" > 
     </Button> 
    </RelativeLayout> 

    <EditText 
     android:id="@+id/editTextMessage" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:layout_margin="3dp" 
     android:hint="@string/editPwd" > 
    </EditText> 

    <Spinner 
     android:id="@+id/spinnerGateway" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:drawSelectorOnTop="true" 
     android:entries="@array/spinnerList" 
     android:prompt="@string/spinnerPrompt" /> 

    <Button 
     android:id="@+id/btnSend" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="3dp" 
     android:text="@string/StrbtnSend" > 
    </Button> 

    <TextView 
     android:id="@+id/txtAuthor" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:text="Designed By - Tapan Desai" /> 
</LinearLayout> 

</FrameLayout> 
0

layout_gravity="center"//can also set horizontal or vertical 

을 중심하고 당신이없는 만들기 위해 중력을 버튼 XML에서이 코드를

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:panel="http://schemas.android.com/apk/res-auto" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#CCC" 
android:orientation="vertical" > 

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

    <org.miscwidgets.widget.Panel 
     android:id="@+id/mytopPanel" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="4dip" 
     panel:animationDuration="1000" 
     panel:closedHandle="@drawable/top_switcher_collapsed_background" 
     panel:content="@+id/mypanelContent" 
     panel:handle="@+id/mypanelHandle" 
     panel:linearFlying="true" 
     panel:openedHandle="@drawable/top_switcher_expanded_background" 
     panel:position="top" > 

     <Button 
      android:id="@+id/mypanelHandle" 
      android:layout_width="fill_parent" 
      android:layout_height="33dip" 
      android:gravity="center" /> 

     <LinearLayout 
      android:id="@+id/mypanelContent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <EditText 
       android:id="@+id/editTextUserName" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:layout_marginTop="6dp" 
       android:hint="@string/editUserName" > 
      </EditText> 

      <EditText 
       android:id="@+id/editTextPassword" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:hint="@string/editUserPwd" > 
      </EditText> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#323299" 
       android:gravity="center" 
       android:padding="4dip" 
       android:text="@string/drpDwnTxt" 
       android:textColor="#eee" 
       android:textSize="16dip" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </org.miscwidgets.widget.Panel> 

    <EditText 
     android:id="@+id/editTextNumber" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="3dp" 
     android:layout_marginTop="6dp" 
     android:hint="@string/editNumber" > 
    </EditText> 

    <EditText 
     android:id="@+id/editTextMessage" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:layout_margin="3dp" 
     android:hint="@string/editPwd" > 
    </EditText> 

    <Spinner 
     android:id="@+id/spinnerGateway" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:drawSelectorOnTop="true" 
     android:entries="@array/spinnerList" 
     android:prompt="@string/spinnerPrompt" /> 

    <Button 
     android:id="@+id/btnSend" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="3dp" 
     android:onClick="save" 
     android:text="@string/StrbtnSend" > 
    </Button> 
</LinearLayout> 

</FrameLayout> 
+0

나는 코드를 시도했지만 여전히 변경되지 않았습니다. 레이아웃은 여전히 ​​동일합니다 .. –

-1

제거 패딩을 변경하고 설정하려고하세요 당신이 그것을 접근하고있는 당신의 자바 클래스에서 여백 또는 여백을 설정하는 것.

+1

이것은 낮은 품질의 답변입니다. 개선 또는 삭제에 대해 생각하십시오. – keyboardsurfer

+0

내 대답을 편집했습니다 –

+0

@mindFreezer 귀하의 제안에 따라 변경했지만 여전히 변경 사항이 없습니다. 레이아웃은 여전히 ​​동일하다. –

관련 문제