2012-10-25 103 views
0

我有一個簡單的表格和一個用於滾動TableRowscrollView。我還添加了頁腳,問題是我需要知道頁腳的大小,所以我可以將android:layout_marginBottom="<size of footerbar>添加到我的scrollView中。那麼我怎樣才能得到頁腳欄佈局的高度呢?請幫幫我。獲取具有wrap_content屬性的佈局的高度

這是我footerbar代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@color/btnColor" 
android:orientation="horizontal" > 


<Button 
    android:id="@+id/previous" 
    style="@style/pagingBarBtnAttr" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/choose_color_btn" 
    android:drawableLeft="@drawable/previous" 
    android:text="Previous" /> 

<TextView 
    android:id="@+id/pageNo" 
    style="@style/pagingBarBtnAttr" 
    android:layout_centerHorizontal="true" 
    android:text="Page No. 1" /> 

<Button 
    android:id="@+id/next" 
    style="@style/pagingBarBtnAttr" 
    android:layout_alignParentRight="true" 
    android:background="@drawable/choose_color_btn" 
    android:drawableRight="@drawable/next" 
    android:text="Next" /> 

現在作爲一個和上一個按鈕有一個可繪製,使他們有提拉根據設備尺寸,以便頁腳欄具有不固定值的身高,所以我怎麼能得到它的身高,所以我可以提供margin_bottom的價值。在此先感謝..

+2

u能張貼什麼ü做了設置其layout_above財產爲頁腳? – AkashG

回答

1

請參閱下面的代碼

首先添加頁腳在XML文件中,並集其alignParentBottom爲true。

然後添加滾動視圖,並與頁腳ID

<LinearLayout 
    android:id="@+id/imgFooter" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" /> 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/imgFooter" 
    android:layout_below="@id/nav_bar_header" 
    android:layout_centerHorizontal="true" 
    android:padding="5dp" > 
</ScrollView> 
+0

我曾試過,因爲我的佈局非常複雜,它根本不工作,但今天它通過應用ur邏輯工作。非常感謝你.. –

1

使用視圖的getLayoutParams()方法,你可以從PARAMS高度:)

1
oldLayout = (android.widget.RelativeLayout.LayoutParams) view.getLayoutParams(); 
Width = oldLayout.width; 
2

使用ViewTreeObserver爲你的佈局時使用的頁腳

ViewTreeObserver vto = layout.getViewTreeObserver(); 
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      //Here you can get dimension of view 
         //This method will called after screen created 
     } 
    }); 
相關問題