我有一个Actionbar和一些片段.问题是我的主屏幕.左侧有一个概述片段,右侧有一个细节片段.我的TabListener是动态的,所以我想以编程方式设置我的布局的权重.每当我尝试获取LinearLayout的Layoutparams时,我都会遇到ClassCastException:
12-22 16:00:37.620: W/System.err(7235): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
12-22 16:00:37.625: W/System.err(7235): at com.coover.eu.lostandfound.ListSearchFragment.onViewCreated(ListSearchFragment.java:184)
12-22 16:00:37.625: W/System.err(7235): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
12-22 16:00:37.630: W/System.err(7235): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
12-22 16:00:37.630: W/System.err(7235): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
12-22 16:00:37.630: W/System.err(7235): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
12-22 16:00:37.630: W/System.err(7235): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
12-22 16:00:37.630: W/System.err(7235): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
12-22 16:00:37.635: W/System.err(7235): at android.app.Activity.performStart(Activity.java:5216)
12-22 16:00:37.635: W/System.err(7235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
12-22 16:00:37.635: W/System.err(7235): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
12-22 16:00:37.635: W/System.err(7235): at android.app.ActivityThread.access$700(ActivityThread.java:140)
12-22 16:00:37.635: W/System.err(7235): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
12-22 16:00:37.640: W/System.err(7235): at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 16:00:37.640: W/System.err(7235): at …Run Code Online (Sandbox Code Playgroud) android classcastexception android-linearlayout android-framelayout
我使用了一层具有半透明背景的framelayout来创建叠加层.但是此叠加层不会阻止触摸事件与其下方的视图进行交互.应如何创建阻止所有触摸事件的叠加层?
我在根视图中有一个FrameLayout(线性:垂直),我根据用户输入使用它来保存不同的片段.FrameLayout小于背景,因此它似乎是"浮动".
如何围绕FrameLayout的角落?
进入FrameLayout内部的碎片不是图片,所以我无法裁剪它们.
我想以编程方式在FrameLayout中添加一个视图,并将其放置在布局中具有特定宽度和高度的特定点.FrameLayout支持这个吗?如果没有,我应该使用中间ViewGroup来实现这一目标吗?
int x; // Can be negative?
int y; // Can be negative?
int width;
int height;
View v = new View(context);
// v.setLayoutParams(?); // What do I put here?
frameLayout.addView(v);
Run Code Online (Sandbox Code Playgroud)
我最初的想法是向FrameLayout添加一个AbsoluteLayout并将视图放在AbsoluteLayout中.不幸的是,我刚刚发现AbsoluteLayout已被弃用.
任何指针都将非常感激.谢谢.
我正确定了一个主要布局,它有一个框架,一个框架在那个框架中,然后在底部有一个水平滚动视图和一堆按钮.单击按钮时,框架的内容应更改为新表,就像在选项卡布局教程中选择不同选项卡一样(不使用选项卡布局,因为我有许多不适合屏幕的按钮,除非滚动)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.2"
android:padding="5dp" android:background="@color/white">
<TableLayout android:id="@+id/Jobs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*">
<TableRow android:id="@+id/JobRow" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/JobID" android:layout_column="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/JobStatus" android:layout_column="2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/Customer" android:layout_column="3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/Department" android:layout_column="4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/DocType" android:layout_column="5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
</TableRow>
</TableLayout>
</FrameLayout>
<HorizontalScrollView
android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="bottom" android:scrollbars="none">
<LinearLayout
android:orientation="horizontal" android:layout_height="wrap_content"
android:layout_width="fill_parent">
<ImageButton android:id="@+id/batching" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/batching"></ImageButton>
<ImageButton android:id="@+id/merging" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/merging"></ImageButton>
<ImageButton android:id="@+id/processing" …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
FrameLayout game = new FrameLayout(this);
LinearLayout gameWidgets = new LinearLayout (this);
game.addView(gameWidgets);
Run Code Online (Sandbox Code Playgroud)
如何在FrameLayout的底部设置LinearLayout?
我正在做一个增强现实应用程序,我需要在摄像机视图上显示一些对象.我正在创建一个FrameLayout,我添加了我的相机视图,然后我添加了我的AR对象(现在我正在尝试使用TextView).在TextView下面的代码中我添加到我的FrameLayout没有显示...
有人可以帮忙吗?一旦我fs出现,我怎么能以编程方式改变它的位置?
UPDATE
我尝试使用ImageView而不是TextView,它可以工作......为什么!?
public class ARActivity extends Activity{
private CBCameraView cv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cv = new CBCameraView(this);
FrameLayout rl = new FrameLayout(this);
rl.addView(cv, GlobalVars.screenWidth, GlobalVars.screenHeight);
setContentView(rl);
// this works...
/*ImageView fs = new ImageView(this);
fs.setImageResource(R.drawable.icon);
rl.addView(fs);*/
TextView fs = new TextView(this);
fs.setText("Bar seco");
fs.setTextColor(android.R.color.white);
fs.setTextSize(1,14);
fs.setLayoutParams(new ViewGroup.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rl.addView(fs);
}
}
Run Code Online (Sandbox Code Playgroud) int mColor = 0xff00ff00;
remoteView.setInt(R.id.framelayout1, "setBackgroundResource", android.R.color.white);
Run Code Online (Sandbox Code Playgroud)
如何使用mColor设置颜色?
FrameLayout在Android中有什么用途?是否有针对其设计的特定方案?
在我的Android应用程序中,我有一个场景,我必须显示两个ImageView,一个在另一个.这是一个.png图像文件,在此图像上可以绘制9个补丁.
ViewGroup我应该为此目的使用哪个:RelativeLayout或FrameLayout?
我还想知道ViewGroup应该使用每个s 的不同场景.
android android-relativelayout android-viewgroup android-framelayout
我试图FrameLayout用我自己的颜色设置我的backgroundcolor .
我创建了一个.xml包含我自己颜色的文件.这里是:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
<color name="orange">#FF7D00</color>
<color name="yellow">#FFFF00</color>
<color name="green">#00FF00</color>
<color name="blue">#00B4FF</color>
<color name="black">#000000</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
这里是我试图设置backgroundcolor的代码,但是当我运行应用程序时,FrameLayout它总是灰色的,为什么?:
FrameLayout MyFrameLayout = new FrameLayout(this);
LayoutParams MyFrameLayoutParam = new LayoutParams(LayoutParams.FILL_PARENT, 200);
MyFrameLayout.setLayoutParams(MyFrameLayoutParam);
MyFrameLayout.setBackgroundColor(R.color.red);
Parent.addView(MyFrameLayout);
Run Code Online (Sandbox Code Playgroud)