【问题标题】:How to inflate view to bottom如何将视图膨胀到底部
【发布时间】:2014-08-10 00:04:10
【问题描述】:

我正在尝试将 tabhost 动态膨胀到视图的底部;但是,无论我做什么,它都会被发送到顶部。

    RelativeLayout item = (RelativeLayout) findViewById(R.id.messagesactivityview);
    View child = getLayoutInflater().inflate(R.layout.bottombartabs, null);
    item.addView(child);
    maketabs();

这是我用来膨胀的代码,这是我要膨胀的 tabhost 的 xml 文件(请注意,我已将 layout_alignParentBottom 设置为 true,但它仍然不起作用)

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhosty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >

<ImageButton
    android:id="@+id/switchtomessages"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_marginLeft="-3.5dip"
    android:layout_marginRight="-3.5dip"
    android:layout_weight="1"
    android:background="@drawable/messages_icon" >
</ImageButton>

<ImageButton
    android:id="@+id/switchtorequests"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_marginLeft="-3.5dip"
    android:layout_marginRight="-3.5dip"
    android:layout_weight="1"
    android:background="@drawable/friend_request_icon" >
</ImageButton>

<ImageButton
    android:id="@+id/switchtofriends"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_marginLeft="-3.5dip"
    android:layout_marginRight="-3.5dip"
    android:layout_weight="1"
    android:background="@drawable/friends_icon" >
</ImageButton>

<ImageButton
    android:id="@+id/uselesstab"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_marginLeft="-3.5dip"
    android:layout_marginRight="-3.5dip"
    android:layout_weight="1"
    android:background="@drawable/settings_icon" >
</ImageButton>

</LinearLayout>

如何发送到底部

【问题讨论】:

标签: android android-linearlayout android-inflate android-relativelayout


【解决方案1】:

把代码改成

RelativeLayout item = (RelativeLayout) findViewById(R.id.messagesactivityview);
getLayoutInflater().inflate(R.layout.bottombartabs, item);

如果没有任何已知的父级,您在 XML 树的根元素上声明的所有 LayoutParams 都将被丢弃。

【讨论】:

  • 他们为什么要这样做?请解释为什么这是有效的。
猜你喜欢
  • 2018-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
相关资源
最近更新 更多