1
<RelativeLayout 
     android:id="@+id/OtherWeatherInfo_main" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="@dimen/margin_space" 
     android:layout_marginLeft="@dimen/margin_space" 
     android:layout_marginRight="@dimen/margin_space" > 

     <RelativeLayout 
      android:id="@+id/OtherWeatherInfo" 
      android:layout_width="@dimen/weather_space" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:gravity="center_vertical" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/rect_block" > 

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

       <TextView 
        android:id="@+id/humidityTitle" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:text="@string/str_humidity" 
        android:textSize="@dimen/weather_size" 
        android:textStyle="bold" > 
       </TextView> 

       <TextView 
        android:id="@+id/humidityValue" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:text="@string/str_no_data" 
        android:textColor="@color/color_white" 
        android:textStyle="bold" > 
       </TextView> 
      </LinearLayout> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/OtherWeatherInfo2" 
       android:layout_width="@dimen/weather_space" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:gravity="center_vertical" 
       android:layout_toRightOf="@+id/OtherWeatherInfo" 
       android:background="@drawable/rect_block" > 

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

        <TextView 
         android:id="@+id/visiTitle" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_horizontal" 
         android:text="@string/str_visi" 
         android:textSize="@dimen/weather_size" 
         android:textStyle="bold" /> 

        <TextView 
         android:id="@+id/visiValue" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_horizontal" 
         android:text="@string/str_no_data" 
         android:textColor="@color/color_white" 
         android:textStyle="bold" /> 
       </LinearLayout> 


     </RelativeLayout> 
    </RelativeLayout> 

Приведенных выше код написан мною для достижения следующего рисунка: enter image description here .О что я достижением является это: enter image description here или это: enter image description here.Выравнивание два Relative расположения в пределах основной относительной компоновки

У меня нет абсолютно никакого понятия о том, что это ошибка, которую я здесь делаю ?? Я только с помощью основной относительной раскладку OtherWeatherInfo_main и в том, что я встраивание двух относительных макетов для представления двух атрибутов погоды. @ dimen/weather_space - 145 дп. Я не могу выровнять два относительных макета в основном макете одинаково. Любая помощь будет оценена.

+1

Вы можете попробовать обернуть два относительных макета внутри LinearLayout горизонтальной ориентацией и дать двум относительным макетам равный вес. – JDJ

+0

JDJ ... ты красотка ... теперь он работает как charm.post это как ответ, и я приму это – kgandroid

+0

Рад, что я мог бы помочь. Удачи с вашим приложением. – JDJ

ответ

1

Wrap два RelativeLayouts внутри LinearLayout с горизонтальной ориентацией, а затем назначить как на RelativeLayouts равного веса.

В общем, что-то вроде этого:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weight="0.5" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weight="0.5" /> 

</LinearLayout> 
0

Удалить или этот

android:layout_alignParentRight="true" 

или это

android:layout_toRightOf="@+id/OtherWeatherInfo" 

из вашего второго макета.

Также вы можете обернуть оба ваши RelativeLayouts горизонтальной LinearLayout и использовать андроид: layout_weight атрибут

+0

Спасибо. Проблема решена. – kgandroid

0

Попробуйте этот путь, если вы бледный достигли своей конструкции с использованием LinearLayout.

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


    <TextView 
     android:id="@+id/txtCityName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Kolkata"/> 

    <ImageView 
     android:id="@+id/imgWeather" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" 
     android:layout_marginTop="20dp"/> 

    <TextView 
     android:id="@+id/txtTemprature" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="28 C" 
     android:layout_margin="10dp"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp"> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="vertical" 
      android:gravity="center"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Humidity"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="29"/> 
      </LinearLayout> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="vertical" 
      android:layout_marginLeft="20dp" 
      android:gravity="center"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Humidity"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="29"/> 
     </LinearLayout> 
     </LinearLayout> 

    <TextView 
     android:id="@+id/txtDateTime" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Fri 28" 
     android:layout_margin="10dp"/> 

</LinearLayout> 
Смежные вопросы