2016-12-15 91 views
0

調試我的程序並在手機上運行後,我的手機無法準確顯示我在Android Studio上設計的內容。當使用相對佈局時,現在當我切換到約束佈局時,它會顯示查找。問題發生。手機無法顯示android應用程序顯示在Android Studio中當調試

圖1是在Android Studio和圖2把我的應用程序的設計意圖的快照是從我的手機本身

Intended Design (Fig 1) Outcome image (Fig 2)

XML代碼

採取的申請結果
<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.jasonkym.safstrengthcounter.MainActivity" 
android:background="@android:color/background_dark"> 

<TextView 
    android:text="No. of blank files:" 
    android:layout_width="84dp" 
    android:layout_height="41dp" 
    android:id="@+id/tvtNoOfBlankFiles" 
    android:textStyle="normal|bold" 
    android:textColor="@android:color/holo_orange_light" 
    tools:layout_editor_absoluteY="160dp" 
    tools:layout_editor_absoluteX="25dp" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/etxNoOfBlankFiles" 
    android:textColor="@android:color/holo_green_dark" 
    android:text="0" 
    android:textStyle="normal|bold|italic" 
    tools:layout_editor_absoluteY="158dp" 
    tools:layout_editor_absoluteX="117dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/tvtResults" 
    android:textSize="24sp" 
    android:textStyle="normal|bold" 
    android:textColor="@android:color/holo_blue_bright" 
    tools:layout_editor_absoluteX="121dp" 
    tools:layout_editor_absoluteY="415dp" /> 

<TextView 
    android:text="No. of people per column:" 
    android:layout_width="88dp" 
    android:layout_height="43dp" 
    android:id="@+id/tvtNoOfPeoplePerRow" 
    android:textStyle="normal|bold" 
    android:textColor="@android:color/holo_orange_light" 
    tools:layout_editor_absoluteX="25dp" 
    tools:layout_editor_absoluteY="234dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SAF Strength Counter" 
    android:id="@+id/tvtStrengthCounterLabel" 
    android:textStyle="normal|bold" 
    android:textSize="30sp" 
    android:textColor="@android:color/holo_red_dark" 
    tools:layout_editor_absoluteX="35dp" 
    tools:layout_editor_absoluteY="32dp" /> 

<TextView 
    android:text="Made by PTE Koh Yi Min Jason" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/tvtMadebyKohYiMinJason" 
    tools:layout_editor_absoluteY="478dp" 
    tools:layout_editor_absoluteX="84dp" /> 

<TextView 
    android:text="No. of people behind:" 
    android:layout_width="87dp" 
    android:layout_height="44dp" 
    android:id="@+id/tvtNoOfPeopleBehind" 
    android:textStyle="normal|bold" 
    android:textColor="@android:color/holo_orange_light" 
    tools:layout_editor_absoluteX="23dp" 
    tools:layout_editor_absoluteY="314dp" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/etxNoOfPeopleBehind" 
    android:textStyle="normal|bold|italic" 
    android:text="0" 
    android:textColor="@android:color/holo_green_dark" 
    tools:layout_editor_absoluteY="315dp" 
    tools:layout_editor_absoluteX="118dp" /> 

<TextView 
    android:text="No. of column:" 
    android:layout_width="82dp" 
    android:layout_height="43dp" 
    android:id="@+id/tvtNumberOfRows" 
    android:textStyle="normal|bold" 
    android:textColor="@android:color/holo_orange_light" 
    tools:layout_editor_absoluteX="27dp" 
    tools:layout_editor_absoluteY="91dp" /> 

<Button 
    android:text="Calculate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/btnCalculate" 
    tools:layout_editor_absoluteY="407dp" 
    tools:layout_editor_absoluteX="236dp" /> 

<TextView 
    android:text="Result:" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/tvtResultsLabel" 
    android:textSize="24sp" 
    android:textStyle="normal|bold" 
    android:textColor="@android:color/holo_orange_light" 
    tools:layout_editor_absoluteY="415dp" 
    tools:layout_editor_absoluteX="26dp" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/etxNoOfRows" 
    android:textColor="@android:color/holo_green_dark" 
    android:text="0" 
    android:textStyle="normal|bold|italic" 
    tools:layout_editor_absoluteY="91dp" 
    tools:layout_editor_absoluteX="115dp" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/etxNoOfPeoplePerRow" 
    android:textColor="@android:color/holo_green_dark" 
    android:text="0" 
    android:textStyle="normal|bold|italic" 
    tools:layout_editor_absoluteY="234dp" 
    tools:layout_editor_absoluteX="121dp" /> 


</android.support.constraint.ConstraintLayout> 

回答

0

我覺得首先你必須採取的相對和約束佈局的想法,然後開始改變你的代碼。下面給出的鏈接將幫助您:

Differences between ConstraintLayout and RelativeLayout

+0

圖1中的屏幕截圖是ConstraintLayout中應用程序的預期設計。不應該我的手機顯示與我在工作室設計的內容完全一樣,無論它是以相對還是約束佈局設計?我是否必須爲約束佈局添加更多行代碼才能使其顯示在工作室中?我覺得是這樣的,因爲看起來我的所有EditText和TextView都在屏幕的左上角,我必須輸入一行或兩行代碼才能將Widget和TextView放置在預期的位置。 –

+0

給我你的xml代碼。 –

0

我希望這是幫助you.`

<Button 
    android:id="@+id/btn_search_back" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@color/color_green" 
    android:elevation="@dimen/card_elivation" 
    android:text="@string/back" 
    android:textColor="@color/color_white" 
    android:textStyle="bold" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" /> 

<ScrollView 
    android:id="@+id/layout_show_response" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintBottom_toTopOf="@+id/btn_search_back"> 
    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.CardView 
      android:id="@+id/cv_search_for" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/margin_medium" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      card_view:cardBackgroundColor="@color/color_simple_gray"> 

      <android.support.constraint.ConstraintLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <TextView 
        android:id="@+id/textView" 
        style="@style/dialog_text_view" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:text="@string/you_ask_for" 
        android:textAllCaps="true" 
        android:textColor="@color/color_black" 
        android:textStyle="bold" 
        tools:layout_editor_absoluteY="40dp" 
        tools:layout_editor_absoluteX="15dp" /> 

       <TextView 
        android:id="@+id/lbl_ask_for" 
        style="@style/dialog_text_view" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:paddingBottom="@dimen/view_padding_extra_small" 
        android:text="Ask For" 
        android:textColor="@color/color_darker_gray" 
        app:layout_constraintTop_toBottomOf="@+id/textView" 
        tools:layout_editor_absoluteX="15dp" /> 

      </android.support.constraint.ConstraintLayout> 
     </android.support.v7.widget.CardView> 

     <android.support.v7.widget.CardView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/margin_medium" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/cv_search_for" 
      card_view:cardBackgroundColor="@color/color_simple_gray"> 

      <android.support.constraint.ConstraintLayout 
       android:id="@+id/cl_result" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <TextView 
        android:id="@+id/textView2" 
        style="@style/dialog_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/result" 
        android:textAllCaps="true" 
        android:textColor="@color/color_black" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/lbl_reply" 
        style="@style/dialog_text_view" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:paddingBottom="@dimen/view_padding_extra_small" 
        android:text="Result" 
        app:layout_constraintTop_toBottomOf="@+id/textView2" 
        android:textColor="@color/color_darker_gray" /> 

       <LinearLayout 
        android:id="@+id/layout_img" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        app:layout_constraintTop_toBottomOf="@+id/lbl_reply" 
        app:layout_constraintLeft_toLeftOf="parent" 
        app:layout_constraintRight_toRightOf="parent" 
        android:visibility="gone" 
        android:orientation="horizontal"> 

        <ImageView 
         android:id="@+id/iv_show_img" 
         android:layout_width="@dimen/layout_width_medium" 
         android:layout_height="@dimen/layout_height_medium" 
         android:layout_gravity="center" 
         android:layout_margin="@dimen/view_margin_nano" 
         android:background="@mipmap/iv_pasted_icon" /> 

        <ImageView 
         android:id="@+id/iv_show_img_icon" 
         android:layout_width="@dimen/layout_width_medium" 
         android:layout_height="@dimen/layout_height_medium" 
         android:layout_gravity="center" 
         android:layout_margin="@dimen/view_margin_nano" 
         android:background="@mipmap/iv_pasted_img" /> 
       </LinearLayout> 


      </android.support.constraint.ConstraintLayout> 
     </android.support.v7.widget.CardView> 
    </android.support.constraint.ConstraintLayout> 


    </ScrollView> 

`

0

我已經解決了問題。使用ConstraintLayout時需要添加約束。它不會像Studio中顯示的那樣顯示而沒有限制。

我可以問有沒有我可以在那裏我設計一個表單應用程序只需拖放就在窗口的Visual Studio設計的應用程序,並沒有添加任何約束的方法嗎?有沒有可以讓我這樣做的佈局?

相關問題