2016-07-20 5 views
1

私はLinearLayoutを持っており、彼のプロフィールを編集するための連絡フォームのようです。しかし、layout_weightに与えるサイズに関係なく、editTextのサイズは変わりません。助けを求めるTyvm!Layout_weight in LinearLayout with ScrollView

<?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:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/first_grey" 
     android:orientation="vertical" 
     tools:ignore="ContentDescription"> 

    <include 
     android:id="@+id/tool_bar" 
     layout="@layout/toolbar_all_activities" /> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="none" 
     android:fillViewport="true"> 

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

      <LinearLayout 
       android:id="@+id/viewUploadPicture" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="25" 
       android:layout_marginTop="20dp" 
       android:clickable="true" 
       android:orientation="horizontal"> 

       <de.hdodenhof.circleimageview.CircleImageView 
        android:id="@+id/imgUserProfile" 
        android:layout_width="0dp" 
        android:layout_height="90dp" 
        android:layout_gravity="center_horizontal" 
        android:layout_weight="0.5" 
        android:src="@drawable/skate_boarder" /> 

       <TextView 
        android:layout_width="0dp" 
        android:layout_height="80dp" 
        android:layout_marginEnd="15dp" 
        android:layout_marginRight="15dp" 
        android:layout_weight="0.5" 
        android:gravity="center_vertical|start" 
        android:text="@string/user.edit.upload_photo" 
        android:textColor="@color/fourth_grey" 
        android:textSize="18sp" /> 

      </LinearLayout> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.first_name" /> 

      <EditText 
       android:id="@+id/txtEditProfileFirstName" 
       style="@style/editTextRoundGrey" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="50" /> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.last_name" /> 

      <EditText android:id="@+id/txtEditProfileLastName" 
       style="@style/editTextRoundGrey" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="50" /> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.edit.favourite_hobby" /> 

      <EditText 
       android:id="@+id/txtEditProfileFavouriteHobby" 
       style="@style/editTextRoundGrey" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="50" /> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.edit.birthday_date" /> 

      <LinearLayout 
       android:id="@+id/birthdayLayout" 
       android:layout_width="300dp" 
       android:layout_height="0dp" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="50" 
       android:orientation="horizontal"> 

       <EditText 
        android:id="@+id/txtDayBirthdayDate" 
        style="@style/editTextNumberRoundGrey" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="0.2" /> 

       <EditText 
        android:id="@+id/txtMonthBirthdayDate" 
        style="@style/editTextNumberRoundGrey" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_marginLeft="10dp" 
        android:layout_marginStart="10dp" 
        android:layout_weight="0.2" /> 

       <EditText 
        android:id="@+id/txtYearBirthdayDate" 
        style="@style/editTextNumberRoundGrey" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_marginLeft="10dp" 
        android:layout_marginStart="10dp" 
        android:layout_weight="0.5" /> 

      </LinearLayout> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.edit.bio" /> 

      <EditText 
       style="@style/editTextRoundGreyBigger" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="120" /> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.edit.city" /> 

      <EditText 
       android:id="@+id/txtEditProfileCity" 
       style="@style/editTextRoundGrey" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="50" /> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.edit.languages" /> 

      <EditText 
       android:id="@+id/txtEditProfileLanguages" 
       style="@style/editTextRoundGrey" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="50" /> 

      <TextView 
       style="@style/editProfileTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
       android:layout_weight="40" 
       android:text="@string/user.edit.password" /> 

      <EditText 
       android:id="@+id/txtEditProfilePass" 
       style="@style/editTextRoundGrey" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="50" /> 

      <Button 
       android:id="@+id/btnSubmitChangedData" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:layout_marginTop="15dp" 
       android:layout_weight="100" 
       android:padding="10dp" 
       android:background="@color/red" 
       android:text="@string/user.edit.submit" /> 

     </LinearLayout> 

    </ScrollView> 
</LinearLayout> 

答えて

0

のEditText高さを変更するために、あなたはまた、この例は以下の

が役立つかもしれないのmaxHeightなどの属性minHeightのMAXLINESinputTypes、およびtextAppreance属性を、使用することを好む必要がありますあなた:

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:ignore="ContentDescription"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="none" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_marginTop="20dp" 
      android:paddingLeft="5dip" 
      android:paddingRight="5dip" 
      > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="FirstName" /> 

      <!-- Person Name EditText--> 

      <EditText 
       android:id="@+id/txtEditProfileFirstName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxHeight="40dip" 
       android:inputType="textPersonName" 
       android:maxLines="1" 
       android:maxLength="25" 
       android:textAppearance="?android:attr/textAppearanceMedium"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="LastName" /> 

      <EditText android:id="@+id/txtEditProfileLastName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxHeight="40dip" 
       android:inputType="textPersonName" 
       android:maxLines="1" 
       android:maxLength="25" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="Hobby" /> 

      <EditText 
       android:id="@+id/txtEditProfileFavouriteHobby" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxHeight="40dip" 
       android:inputType="text" 
       android:maxLines="2" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="Birthday Date" /> 

      <LinearLayout 
       android:id="@+id/birthdayLayout" 
       android:layout_width="300dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:layout_marginTop="10dp" 
       android:weightSum="1" 
       android:orientation="horizontal"> 
`enter code here`    <EditText 
        android:id="@+id/txtDayBirthdayDate" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.3" 
        android:inputType="number" 
        android:gravity="center" 
        android:layout_gravity="center" 
        android:maxLength="2" 
        /> 

       <EditText 
        android:id="@+id/txtMonthBirthdayDate" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="10dp" 
        android:layout_marginStart="10dp" 
        android:layout_weight="0.3" 
        android:gravity="center" 
        android:layout_gravity="center" 
        android:inputType="number" 
        android:maxLength="2" 
        /> 
       <EditText 
        android:id="@+id/txtYearBirthdayDate" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="10dp" 
        android:layout_marginStart="10dp" 
        android:layout_weight="0.4" 
        android:inputType="number" 
        android:gravity="center" 
        android:layout_gravity="center" 
        android:maxLength="4" 
        /> 
      </LinearLayout> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="Bio" /> 

      <!--MultiLine EdiText--> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textMultiLine" 
       android:minHeight="80dp" 
       android:maxLines="4" 
       android:isScrollContainer="true"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="City" 
       /> 
      <EditText 
       android:id="@+id/txtEditProfileCity" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxHeight="40dip" 
       android:inputType="textPostalAddress" 
       android:maxLines="1" 
       android:maxLength="25" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="Languages" /> 
      <EditText 
       android:id="@+id/txtEditProfileLanguages" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxHeight="40dip" 
       android:inputType="text" 
       android:maxLines="1" 
       android:maxLength="25" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:text="password" /> 
      <!--Password EditText--> 
      <EditText 
       android:id="@+id/txtEditProfilePass" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxHeight="40dip" 
       android:inputType="textPassword" 
       android:maxLines="1" 
       android:maxLength="25" 
       android:textAppearance="?android:attr/textAppearanceMedium"/> 

      <Button 
       android:id="@+id/btnSubmitChangedData" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:layout_marginTop="15dp" 
       android:layout_weight="1" 
       android:padding="10dp" 
       android:background="@color/red" 
       android:text="Submit" /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
+0

私はすでにそれを試しましたが、それは同じままです –

+0

@AntónioVieira、何を試しましたか?下の私の例を見てください。 'android:layout_weight'が効果を持つためには、' android:weightSum'属性を使用する必要があります。 – Vinnie

+0

@AntónioVieira私は自分の答えを編集しました。 # – Sathiamour

0

android:layout_weight属性は、android:weightSum属性とともに使用されます。あなたの子供layout_weightは、その親のレイアウトのweightSumになる必要があります。

layout_weightをXMLコードで何度も使用して、weightSumと宣言しないでください。 android:weightSumがない場合、android:layout_weightは効果を持ちません。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="100"> 

    <EditText 
     android:id="@+id/my_edit_text" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="50" 
     android:hint="type something"> 

    <Button 
     android:id="@+id/my_button" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="50" 
     android:text="a button"> 
</LinearLayout> 

注あなたの子ビューlayout_height sが垂直のLinearLayoutの向きのために"0dp"に設定する必要があります:あなたが均等にまたがるように、親のLinearLayout内の2つのビューがしたい場合たとえば、あなたはこのような何かを行うことができます 。水平方向の場合、子ビュー 'layout_width'を"0dp"に設定します。別の例として

https://stackoverflow.com/a/7452788/4138919

で受け入れ答えを参照してください、私はまた、あなたがlayout_weightのための非浮動小数点値を浮動小数点値を混ぜることに注意してください。読みやすいように、どちらか一方に固執することを検討してください。

+0

私は他のレイアウトでいくつかのテストを行いました。私は質問に言及しています。そして' weightSum'は親にあるサイズを定義すると ' ScrollView')を使用して、 'weight_sum'(' LinearLayout')を指定しています。もし私がこれを好きなら、すべてのサイズは、 'EditText'と他のものでいいでしょう。しかし、この場合、実際には 'match_parent'でなければなりません。なぜなら、' ScrollView'だからです。 –