2015-06-17 2 views
0

Я хочу сделать EditText и кнопку OK той же самой высотой, но всегда получил EditText немного короче, чем Button.Android: Как установить EditText и Button на ту же высоту?

enter image description here

Я гугл и попытался следующим образом без успеха, ничего не изменилось:

  1. установить как EditText и кнопки на тот же высоту в пикселях
  2. оберточной EditText и Баттон в RelativeLayout. Установите высоту RelativeLayout и установить EditText и кнопки как для fillparent высоты
  3. набора AlignTop и AlignBottom на кнопке

Тема: android:theme="@android:style/Theme.NoTitleBar.Fullscreen

Может кто-то пожалуйста, помогите мне в этом? Благодаря!

Вот XML:

<RelativeLayout android:id="@+id/login_layout_ipAddr" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:background="#CEE6F0" 
     android:visibility="invisible"> 

     <RelativeLayout android:id="@+id/login_layout_inner_ipAddr" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <EditText android:id="@+id/login_text_ipAddr" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:inputType="text" 
       android:textSize="5pt" 
       android:hint="@string/login_text_ipAddr" /> 

      <Button android:id="@+id/login_btn_ipAddr" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:background="#00ABDF" 
       android:textColor="#FFFFFF" 
       android:text="@string/login_btn_ipAddr" 
       android:onClick="updateIPaddr"/> 

     </RelativeLayout> 


    </RelativeLayout> 
+0

не размещать весь макет. – Attaullah

ответ

0

У меня есть правильный код так попробуйте это ...

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
android:id="@+id/login_layout_ipAddr" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerInParent="true" 
android:background="#CEE6F0" 
android:visibility="invisible"> 

<LinearLayout 
    android:id="@+id/login_layout_inner_ipAddr" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:orientation="horizontal" 
    android:weightSum="2"> 

    <EditText 
     android:id="@+id/login_text_ipAddr" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1.8" 
     android:inputType="text" 
     android:textSize="5pt"/> 

    <Button 
     android:id="@+id/login_btn_ipAddr" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.2" 
     android:background="#00ABDF" 
     android:textColor="#FFFFFF"/> 
</LinearLayout> 

0

вы можете поместить как текст редактирования и кнопки в TableRow и контролировать их пространство с весом, это облегчило бы этот процесс.

0

Попробуйте использовать LinearLayout вместо этого на RelativeLayout

enter image description here

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

     <LinearLayout 
      android:id="@+id/login_layout_inner_ipAddr" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:background="#CEE6F0" 
      android:weightSum="6" > 

      <EditText 
       android:id="@+id/login_text_ipAddr" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="5" 
       android:hint="@string/login_text_ipAddr" 
       android:inputType="text" 
       android:textSize="5pt" /> 

      <Button 
       android:id="@+id/login_btn_ipAddr" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="#00ABDF" 
       android:onClick="updateIPaddr" 
       android:text="@string/login_btn_ipAddr" 
       android:textColor="#FFFFFF" /> 
     </LinearLayout> 
    </LinearLayout> 
+0

Привет @Attaullah. Спасибо за ответ. Я попробовал ваш код, но не повезло. – sliter

+0

это вся макет.если вы используете один вид, например дочерний макет, то удалите и xmlns: android = "http://schemas.android.com/apk/res/android" Я уже тестировал этот код ... – Attaullah

0

Установить обивка на кнопку.

<Button android:id="@+id/login_btn_ipAddr" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:background="#00ABDF" 
      android:textColor="#FFFFFF" 
      android:text="@string/login_btn_ipAddr" 
      android:onClick="updateIPaddr" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp"/> 
-1

Чтобы создать кнопку с фиксированной высотой и шириной, вы можете указать значения как в px, так и в dp.

Дает значения в формате dp более удобно, поскольку андроид автоматически масштабирует высоту и ширину в устройствах ldpi, mdpi и hdpi.

<Button 
android:layout_width="100dp" 
android:layout_height="50dp"  
android:text="Click" /> 
+0

он запрашивает формат edittext ... – Attaullah

+0

Поскольку он не может установить editText height ..so, он может установить высоту кнопки. Также его вопрос заключается в том, как установить кнопку и edittext для того же высота?? –

0

Наконец, я решил проблему путем добавления "android:background="#FFFFFF"" к элементу EditText. Но я не знаю, в чем причины такого поведения. Я бы очень признателен, если бы кто-то мог пролить свет на это.

Нет фона:

enter image description here

С фоном:

enter image description here

+0

, но EditText имеют одинаковое положение .. цвет не имеет значения. :) – Attaullah

Смежные вопросы