LinearLayout?bir yüzdesi için bir genişlik tanımlama
Ve alt düğmeleri fill_parent böylece merkezi ve bazı düğmeleri içeren bir LinearLayout için bir yüzde genişlik (70%) tanımlamak istiyorum. İşte bir resim, ne demek istediğimi gösteriyor:
Benim şimdiki düzen bu gibi görünüyor:
<?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:id="@ id/layoutContainer" android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:id="@ id/barContainer" android:orientation="horizontal"
android:layout_height="40dp" android:background="@drawable/titlebackground">
<ImageView android:id="@ id/barLogo" android:src="@drawable/titlelogo"
android:layout_gravity="center_vertical" android:adjustViewBounds="true"
android:layout_height="25dp" android:layout_width="wrap_content"
android:scaleType="fitXY" android:paddingLeft="5dp"></ImageView>
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent" android:gravity="center_horizontal"
android:id="@ id/searchTip" android:text="@string/searchTip"
android:paddingTop="10dp" android:paddingBottom="10dp"></TextView>
<LinearLayout android:layout_height="wrap_content"
android:id="@ id/linearLayout1" android:orientation="vertical" android:layout_width="wrap_content">
<Button android:text="Button" android:id="@ id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:layout_width="wrap_content" android:id="@ id/button2" android:layout_height="wrap_content" android:text="Button"></Button>
<Button android:layout_width="wrap_content" android:id="@ id/button3" android:layout_height="wrap_content" android:text="Button"></Button>
</LinearLayout>
</LinearLayout>
LinearLayout sohbet atıfta kimliği vardır: linearLayout1. Bunu nasıl yapabilirim?
CEVAP
Senin elemanların ağırlık özelliği var. LinearLayout ve set ağırlıkları 0.15, 0.70, 0.15 çocuk olarak üç RelativeLayouts oluşturun. Sonra ikinci RelativeLayout için düğmeleri(ağırlık 0.70 ile) ilave edin.
Bu gibi:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@ id/layoutContainer" android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.7">
<!-- This is the part that's 70% of the total width. I'm inserting a LinearLayout and buttons.-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<Button
android:text="Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<!-- 70% Width End-->
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15">
</RelativeLayout>
</LinearLayout>
Neden sıklet 0.15, 0.7 ve 0.15? Toplam ağırlığı 1 ve 0.7 olduğu için toplam p'tir.
Sonuç:
Edit: tamsayılar yerine yönünü yatay ve dikey olması gerektiğini ifade eden ve @ağırlıklar ondalık olabilir buna dikkat çektiğin için Andrew için @SimonVeloper için Teşekkürler.
Bir hizalamak için nasıl <sayfanın ...
Nasıl bir android genişlik ve yüksekli...
<fieldset> yeniden boyutlandırır...
Nasıl ayarı yanlış LinearLayout perfor...
Ekrana bir görüntü germek için Nasıl g...