我的相对布局包含imageView
,其中包含两个<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rlParent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_marginRight="5dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"/>
</LinearLayout>
</RelativeLayout>
,如下所示。
surfaceView
然后我以编程方式添加了自定义surfaceView
。添加linearLayout
layout_centerInParent
后未显示在center.I尝试通过代码设置mPreview = new CustomSurfaceView(getActivity(),1, CameraPreview.LayoutMode.FitToParent, false,this);
LayoutParams previewLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
mLayout.addView(mPreview, 0, previewLayoutParams);
属性,但它无法正常工作。
请帮帮我。
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("window.scrollBy(0,500)");
var action = new Actions(driver);
var mySlot = driver.FindElement(By.XPath("//div[@ng-repeat='filter in date_filters' and contains(., '29 Dec')]"));
action.MoveToElement(mySlot).Click().Perform();
mLayout是Releativelayout,mPreview是自定义surfaceview
答案 0 :(得分:2)
您的父级布局(此处RelativeLayout
)宽度必须为match_parent
。那么只有您的子布局,centerInParent
才有效。
答案 1 :(得分:0)
试试这个......
<RelativeLayout
android:id="@+id/rlParent">
<LinearLayout
android:id="@+id/rlChild">
......
</LinearLayout>
View mPreview = findViewById(R.id.rlChild);
RelativeLayout.LayoutParams previewLayoutParams = (RelativeLayout.LayoutParams)mPreview.getLayoutParams();
previewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
mPreview.setLayoutParams(previewLayoutParams);
mLayout.addView(mPreview);
答案 2 :(得分:0)
第二行和第三行,你必须写match_parent
。这就是centerinparent
无效的原因。
答案 3 :(得分:-2)
试试这个android:layout_centerHorizontal="true"
代替android:layout_centerInParent="true"