android - 相对布局问题

标签 android android-layout

我正在研究相对布局。基本上我想把我的代码(lnrTicker)和页脚(txtFooter)放在屏幕底部。一切正常文件,除了 ticker 剪掉了 wvRight 元素的一些底部。所以我发现可能我必须将 android:layout_above="@id/lnrTicker", 放在 wvRight 组件中。但每当我这样做时,我都会看到编译错误,指出找不到资源“lnrTicker”。我怎样才能实现布局,或者我在理解 layout_above 时缺少什么。这是我的布局文件

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:background="@color/black">
    <WebView 
        android:id="@+id/wvHeader"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"  
        android:visibility="gone"       
        android:scrollbars="none"/>     
    <WebView 
        android:id="@+id/wvLeft"
        android:layout_width="300dp"
        android:layout_height="fill_parent"
        android:scrollbars="none"
        android:visibility="gone"
        android:layout_below="@id/wvHeader"/>   
    <WebView 
        android:id="@+id/wvRight"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:scrollbars="none"           
        android:layout_toRightOf="@id/wvLeft"
        android:layout_below="@id/wvHeader"
        android:layout_above="@id/lnrTicker"/>
    <LinearLayout 
        android:id="@+id/lnrTicker"
        android:orientation="horizontal" 
        android:layout_width="fill_parent"      
        android:layout_height="60dp"        
        android:layout_below="@id/wvRight"/>
    <TextView
        android:id="@+id/txtFooter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:textSize="8sp"
        android:layout_below="@id/lnrTicker"
        android:layout_alignParentBottom="true"/>   
</RelativeLayout>

是否可以在运行时将 android:layout_above="@id/lnrTicker"添加到 wvRight 组件?

最佳答案

Is it possible to add android:layout_above="@id/lnrTicker", at runtime to wvRight component?

是的。

<WebView android:layout_above="@+id/lnrTicker"

后来

<LinearLayout android:id="@id/lnrTicker"

区别在于您是在 @id/wvRight 中首次声明 android:id因此需要 + .

关于android - 相对布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5677172/

相关文章:

java - 如何在谷歌地图上设置可预测搜索?

android - 改变 ActionBar 的方向

android - 从一个 View 更改为另一个 View onScroll

android - 为什么 Android API 级别 15 中的 "Buttons in button bars should be borderless"?

java - 通过 XML 创建的 UI 对象不会在 Android Marshmallow 中被清除

android - 动态获取布局的高度和宽度

java - Android 无法使用 attrs 值扩充布局文件

java - 具有 Webview 的 IOS 和 Android 应用程序是否仅被视为混合应用程序或 Web 应用程序?

android - 如何在单个 TextView 中显示数组列表中的多行?

android - YouTubePlayerView被com.google.android.youtube.player.YouTubePlayerView遮盖了