1

Android geliştirmede yeni başlayan biriyim, projem iki parça (ev ve alan) kullanarak basit bir kullanıcı arayüzü uygulaması oluşturmamı gerektiriyor. Ev, 5 düğmeli yıldız sayfasını gösterir. Bu düğmelere tıkladığımızda, alan parçasını çağırır ve aşağıdaki alanları gösterecektir:Android stüdyosu, birden fazla metin görünümünü hizalama ve doğrusal düzende metinleri düzenleme (yatay)

İletkenlik: ----, yükseklik: ---- ve vb.

Buradaki sorun, projenin alan parçacığı için yatay hizalamada linelaylayışı kullanmamı gerektirdiğinden, bunu yaptığımda ve düzenleme metin ve metin görünümleri eklediğinde, yatay olarak aynı satırda dizildiğini, ancak ihtiyacım olan şey

iletkenliği (metin görüntüsü) gibi bir şey: bir ve bunun altında yer alan başka görüntülenmesini ___________ (EditText) [başka bir satır] yüksekliği (metin görünümü) ________ (EditText)

vb. SOrry bu basit bir sorun olabilir ama şimdi 2 gün boyunca bu konuda sıkışmış. Yardım beni

aşağıdaki gibi saha fragment.xml benim kodudur: my anlayış içinde ise

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

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hp1_textView" 
    android:id="@+id/hp1_textView" 
    android:textSize="32sp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" /> 

<LinearLayout  android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/hp1_textView" 
    android:layout_centerHorizontal="true" 
    android:id="@+id/linearLayout"> 
    <TextView   android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="@string/conductivity" 
     android:id="@+id/textView"/> 
    <EditText   android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText" 
     android:layout_weight="1" 
     android:hint="@string/conductivity_field" /> 
    <TextView   android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="pH:" 
     android:id="@+id/textView2" /> 
    <EditText   android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText2" 
     android:layout_weight="1" 
     android:hint="0.-14" /> 

</LinearLayout> 
</RelativeLayout> 

THis is how i want it to display

+0

lütfen s Sorunu ima et. Anlayamıyorum. –

+0

bu yüzden doğrusal bir düzende (yatay) olan bir alan parçacığım var, fakat görüntü eklendikçe dizilen metin görünümlerine ve edittexlere ihtiyacım var, bunu nasıl yapabilirim? –

+0

daha iyi bir ekran görüntüsü yakalama –

cevap

5

kullanımı o

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


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:padding="5dp" 
     android:weightSum="2"> 


     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Conductivity (uS): " 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:hint="745.2" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:padding="5dp" 
     android:weightSum="2"> 


     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="pH: " 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:hint="7.1" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:padding="5dp" 
     android:weightSum="2"> 


     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Moisture(%): " 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:hint="0-100" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:padding="5dp" 
     android:weightSum="2"> 


     <TextView 
      android:id="@+id/textVie4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:singleLine="true" 
      android:text="Dissolved oxygen(ppm): " 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:hint="0-100" /> 

    </LinearLayout> 

    <Button 
     android:id="@+id/btn1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:padding="5dp" 
     android:text="Save Log Entry" /> 

    <Button 
     android:id="@+id/btn2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:padding="5dp" 
     android:text="Show Log Entry" /> 


</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:orientation="horizontal" 
    android:padding="5dp" 
    android:weightSum="3"> 


    <Button 
     android:id="@+id/btn3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_weight="1" 
     android:padding="5dp" 
     android:text="Previouse" /> 

    <Button 
     android:id="@+id/btn4" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_weight="1" 
     android:padding="5dp" 
     android:text="Next" /> 


    <Button 
     android:id="@+id/btn5" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_weight="1" 
     android:padding="5dp" 
     android:text="Home" /> 

</LinearLayout> 

</RelativeLayout> 

Ben onun sorunu çözmek umut olduğu gibi kodunuzda bu xml .....

1

android:orientation

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

    <TextView 
     android:id="@+id/hp1_textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="hp1" 
     android:textSize="32sp" /> 

    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="12"> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="2" 
      android:orientation="horizontal" 
      android:weightSum="2"> 

      <TextView 
       android:id="@+id/textView" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="conductivity" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <EditText 
       android:id="@+id/editText" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:hint="conductivity_field" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearLayout2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="2" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="pH:" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <EditText 
       android:id="@+id/editText2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:hint="0.-14" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearLayout3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="2" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="Moisture(%):" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <EditText 
       android:id="@+id/editText3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:hint="0-100" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearLayout4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="2" 
      android:orientation="horizontal" 
      android:weightSum="2"> 

      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="Disolved Oxygen(ppm)" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <EditText 
       android:id="@+id/editText4" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:hint="0-100" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearLayout6" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_weight="2" 
      android:orientation="vertical" 
      android:weightSum="2"> 

      <Button 
       android:id="@+id/Button11" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_gravity="bottom" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="Save log entry" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <Button 
       android:id="@+id/Button12" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_gravity="bottom" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:hint="Show log entries" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearLayout5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_weight="2" 
      android:orientation="horizontal" 
      android:weightSum="3"> 

      <Button 
       android:id="@+id/Button1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="conductivity" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <Button 
       android:id="@+id/Button2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_weight="1" 
       android:hint="conductivity_field" /> 

      <Button 
       android:id="@+id/Button3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_weight="1" 
       android:hint="conductivity_field" /> 
     </LinearLayout> 

    </LinearLayout> 

</LinearLayout> 
+0

kontrol güncellenen cevap @ Janam Rajbhandari –

+0

thanx işe yaradı: D sadece benim projem beni yatay allign blahh blaah kullanmak istedi! Her neyse size bu yardımcı oldu –

+0

Şerefe ... kodlamaya devam. –

0

ile android:weightSum ve LinearLayout aşağıda deneyin senaryonuz doğru, onları’de olduğu gibi birbirinin altında göstermek Sağladığınız, linearLayoutorientation, vertical olarak ayarlanmalıdır. orientationhorizontal'u kullanırsanız, widgets çizimi, widgets telefonunuzu width numaralı telefona tam olarak çizdikten sonra bir sonraki satıra kadar düşer (ve sonra bir sonraki satıra atlar). LinearLayout'un değiştirilmesi gerekir. vertical orientation

<LinearLayout  
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/hp1_textView" 
    android:layout_centerHorizontal="true" 
    android:id="@+id/linearLayout"> 
+0

Daha fazla bilgi için bu sitelere bakın [1] (http://android4beginners.com/2013/07/lesson-2-1-how-to-build-android-app-with-simple-but-powerful-linearlayout-plus- düzen-oryantasyon-boyut olarak-ve-weight-of-elements /) ve [2] (http://developer.android.com/intl/es/guide/topics/ui/layout/linear. html) –

İlgili konular