在我的应用程序中,我有一个布局RelativeLayout,我想在运行时以编程方式设置边距.但是,当我这样做时,它让我ClassCastException说FrameLayout不能投RelativeLayout.我没有使用任何FrameLayout,也没有导入FrameLayout.问题仍然存在.我使用的xml是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_root"
android:background="@color/menu_bg"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/ll_lhs_menu"
android:layout_width="300dip"
android:layout_height="fill_parent"
android:background="@color/menu_bg"
android:orientation="vertical">
.....
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_right"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="@drawable/capture_port"
android:scrollbars="none" >
....
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的onCreate,我将边距设置为父布局:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
_rootLayout = (RelativeLayout) findViewById(R.id.rl_root);
RelativeLayout.LayoutParams _rootLayoutParams = new RelativeLayout.LayoutParams(_rootLayout.getWidth(), _rootLayout.getHeight());
_rootLayoutParams.setMargins(300, 0, 300, 0);
_rootLayout.setLayoutParams(_rootLayoutParams);
}
Run Code Online (Sandbox Code Playgroud)
这是LogCat:
07-18 21:12:39.410: E/AndroidRuntime(7663): FATAL EXCEPTION: …Run Code Online (Sandbox Code Playgroud) android classcastexception android-layout android-relativelayout android-framelayout
我在片段中使用YouTubePlayer(Android api for android)我正在使用YouTube播放器为LinearLayout充气,这样:
fragmentManager = getActivity().getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
player = new YouTubePlayerSupportFragment();
fragmentTransaction.add(R.id.youTubePlayerContainer, player);
fragmentTransaction.commit();
Run Code Online (Sandbox Code Playgroud)
... youTubePlayerContainer是膨胀的LinearLayout
正确检测到播放器,开始播放并在第二站停止播放.日志显示以下内容:
YouTube video playback stopped due to unauthorized overlay on top of player.
The YouTubePlayerView is obscured by android.widget.FrameLayout@4110d1f8.
YouTubePlayerView is completely covered, with the distance in px between each edge of the obscuring view and the YouTubePlayerView being: left: 484, top: 100, right: 100, bottom: 170..
Run Code Online (Sandbox Code Playgroud)
这是我的XML :(其中没有FrameLayout)
<LinearLayout
android:id="@+id/curtain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/withApi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > …Run Code Online (Sandbox Code Playgroud) 我有一个FrameLayout包含一个TextView和两个LinearLayouts:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
... a textview and 2 linearlayouts
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
运行Android Lint后,我收到此警告: This <FrameLayout> can be replaced with a <merge> tag.
为什么会出现此警告?我该怎么做才能解决它(除了忽略)?
这是代码 -
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) searchPin.getLayoutParams();
params.setMargins(135, 176, 0, 0);
//params.leftMargin = 135; // also not worked
//params.topMargin = 376;
searchPin.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)
无论如何,从xml开始工作 -
android:layout_marginLeft="135dp"
Run Code Online (Sandbox Code Playgroud)
可能是什么原因?我错过了什么!
-thnx
任何人都可以帮助我知道如何捕获FrameLayout图像的内容并将其保存到内部或外部存储.
布局时我遇到了一个非常奇怪的问题.它看起来像在eclipse XML编辑器和我的三星galaxy中设计但它在我的旧手机xperia x10 mini中搞砸了.我只能假设这也会在其他设备中出现.
如果有人可以帮忙解决这个问题,我将不胜感激.
以下是两个屏幕截图和XML代码.
它在eclipse布局编辑器和我的三星galaxy S4 mini中看起来如何
它在Sony xperia x10 mini中的外观如何
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_marginTop="7dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View android:layout_marginTop="19dp" android:layout_marginLeft="19dp" android:layout_height="249dp" android:layout_width="2dp" android:background="#B2CFEF"/>
<View android:layout_marginTop="19dp" android:layout_marginLeft="189dp" android:layout_height="249dp" android:layout_width="2dp" android:background="#B2CFEF"/>
<View android:layout_marginTop="18dp" android:layout_marginLeft="20dp" android:layout_height="2dp" android:layout_width="170dp" android:background="#B2CFEF"/>
<View android:layout_marginTop="267dp" android:layout_marginLeft="19dp" android:layout_height="2dp" android:layout_width="171dp" android:background="#B2CFEF"/>
<ImageView style="@style/ta_img" android:id="@+id/ta_lu" android:layout_marginTop="52dp" />
<ImageView style="@style/ta_img" android:id="@+id/ta_lc" android:layout_marginTop="124dp" />
<ImageView style="@style/ta_img" android:id="@+id/ta_ld" android:layout_marginTop="197dp" />
<ImageView style="@style/ta_img" android:id="@+id/ta_ru" android:layout_marginLeft="170dp" android:layout_marginTop="52dp" />
<ImageView style="@style/ta_img" android:id="@+id/ta_rc" android:layout_marginLeft="170dp" android:layout_marginTop="124dp" />
<ImageView …Run Code Online (Sandbox Code Playgroud) android android-layout android-linearlayout android-framelayout android-constraintlayout
我想知道如何在不同于FrameLayout的视图中应用或模拟前景效果,如LinearLayout或RelativeLayout
这就是我现在拥有的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/row_background"
android:foreground="@drawable/foreground_row">
...
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我想要的东西是这样的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/row_background"
app:foreground="@drawable/foreground_row">
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
提前致谢!!
我的应用程序的设计
屏幕 - 1
<NestedScrollview>
<LinearLayout orientation:horizontal">
<RecyclerView-1>
<Framelayout>(contains Recyclerview-2)
</NestedScroll>
Run Code Online (Sandbox Code Playgroud)
屏幕 - 2
<NestedScrollview>
<LinearLayout orientation:horizontal">
<RecyclerView-1>
<Framelayout> (fragment changed, contains Recyclerview-3)
</NestedScroll>
Run Code Online (Sandbox Code Playgroud)
现在,如果用户在屏幕 1 上,则两个 recyclerview 将同时滚动,但在屏幕 2 上,如果用户滚动 RV1,则只有 RV1 会类似地滚动,如果 RV3 滚动,则 RV3 将滚动。尝试了各种停止滚动,但无法停止嵌套滚动视图的滚动。
android android-recyclerview android-framelayout android-nestedscrollview
我正在构建一个MainActivity包含两个片段的Activity的应用程序.我遇到了很多教程,它们FrameLayout用作片段布局的父容器.
但是,我开始知道我仍然可以使用LinearLayout片段的父容器,它完全正常(到目前为止).
我的问题是,是否存在不使用FrameLayout片段布局的父容器的副作用?
如果没有,那么使用FrameLayoutover LinearLayout(或其他可能的布局)作为片段布局的父容器有什么好处.
android android-layout android-linearlayout android-framelayout
我在NestedScrollView中有一个FrameLayout,如
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
Run Code Online (Sandbox Code Playgroud)
但是FrameLayout没有填充NestedScrollView的高度.我该如何解决这个问题?