如何动态地在Android的设置相对布局的高度布局、高度、动态、Android

2023-09-07 08:56:02 作者:无所谓

这个模拟器上而不是在设备上,因为我已经很难codeD工作正常的高度,以365。任何人都可以帮助我在这方面?

This is working fine on emulator but not on the devices because I have hard coded the height to 365. Can anyone help me in this regard?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tab_host"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TabWidget android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@android:id/tabs"
        android:layout_gravity="bottom" />
    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent" android:layout_height="fill_parent" >
        <RelativeLayout android:id="@+id/first_tab"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="365px" >
               <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

<ImageView
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="49px"
android:layout_x="0px"
android:layout_y="0px"
android:background="#39000000"
android:layout_alignParentBottom="true"
>
</ImageView>
<ImageButton
android:id="@+id/btnFB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/fb"
android:background="#00000000"
android:layout_alignRight="@+id/widget31"
android:layout_alignParentBottom="true"
>
</ImageButton>
<TextView   
   android:id="@+id/myTextView1"   
   android:layout_height="wrap_content"   
   android:layout_width="wrap_content"   
   android:text="Share"
   android:textColor="#111111"
   android:textSize="14pt"
   android:paddingBottom="5px"
   android:layout_alignLeft="@+id/widget31"
   android:layout_alignParentBottom="true"
    /> 

<ImageButton
android:id="@+id/btnTwitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/twitter"
android:visibility="invisible"
android:background="#00000000"
android:layout_alignRight="@+id/widget31"
android:layout_alignParentBottom="true"
>
</ImageButton>

            <!-- Replace TextView with your layout content for this tab -->
        </RelativeLayout>
        <LinearLayout android:id="@+id/second_tab"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
            <ScrollView   
    android:id="@+id/ScrollView01"  
  android:layout_height="365px"   
  android:layout_width="fill_parent">  



 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webviewForRSS"
android:layout_width="fill_parent"
android:layout_height="365px"
android:background="#98012E"
/>

 </ScrollView>
            <!-- Replace TextView with your layout content for this tab -->
        </LinearLayout>

        <LinearLayout android:id="@+id/edit_item_text_tab"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </FrameLayout>
</TabHost>
</RelativeLayout>

感谢。

推荐答案

您可以通过动态地不同的方式改变布局高度-----

You can change the layout height dynamically through different ways-----

首先,

getLayoutParams().height= x;
requestLayout(); or invalidate(); 

其次,

 first_tab.setHeight(int pixels);

尝试使用方式的人.......

Try using anyone of the way.......

 
精彩推荐
图片推荐