Android 如何以编程方式更改线性布局在相关图表中的顶部位置
我想更改RelativeLayout内部的线性布局。 但是当我使用settop时,它不工作!!! 我找不到好的教程Android 如何以编程方式更改线性布局在相关图表中的顶部位置,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我想更改RelativeLayout内部的线性布局。 但是当我使用settop时,它不工作!!! 我找不到好的教程 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:paddin
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:padding="5dp" >
<LinearLayout
android:id="@+id/remotebox"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/remote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WWWWWWWWWWW"
android:textSize="30dp"
android:layout_gravity="left"
/>
<TextView
android:id="@+id/ver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TTTTTT"
android:layout_gravity="right"
/>
</LinearLayout>
我想更改“@+id/remotebox”的布局位置、宽度和高度。
关于这个问题有什么建议,或者是好教程的链接?
抱歉英语不好试试这个
LinearLayout linearLayout= (LinearLayout)findViewById(R.id.remotebox);
linearLayout.getLayoutParams().width=50;//dimensions
linearLayout.requestLayout();
linearLayout.setTranslationY(800);//position
希望这能对您有所帮助。在我的例子中,以下代码起作用:
// step1. get the target view
LinearLayout thisView = (LinearLayout)rootView.findViewById(R.id.tab3_bind_device_page);
// step2. get the LayoutPrams instance.
// notice: in this case, the LinearLayout is wrapped by this RelativeLayout,
// so here we have to use the RelativeLayout.LayourParams
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
// change the margins
// in fact you should convert -25f from "px" to "dp", if possible.
lp.setMargins(0, -25f, 0, 0);
thisView.setLayoutParams(lp);
你想把布局放在哪里?@SiweiShen申思维 : 我真的不记得这个案例,但尝试在ViewTreeObserver.OnPreDrawListener中更改它。。。我不知道为什么,但你的回答很好。也许我的情况和其他人不一样。谢谢!