这是我的XML 2 LinearLayouts.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/ll_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout
android:id="@+id/ll_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我从http://android.arnodenhond.com/components/graphview下载了GraphView .这个类扩展了View.我基本上想要初始化2个图表
String[] verlabels = new String[]{"aim", "25%", "50%", "75%", "start"};
String[] horlabels = new String[]{"this", "max"};
float[] values = new float[]{2.0f, 6.0f};
aaaGraphView graphView = new aaaGraphView(this, values, "Graph One",
horlabels, verlabels, aaaGraphView.BAR);
float[] values2 = new float[]{1.0f, 12.0f};
aaaGraphView graphView2 = new aaaGraphView(this, values2, "Graph Two",
horlabels, verlabels, aaaGraphView.BAR);
Run Code Online (Sandbox Code Playgroud)
然后膨胀graphView到ll_one,graphView2 …
android graph android-linearlayout android-inflate layout-inflater
我似乎不明白是否可以将一项活动(包括)扩展到另一项活动中.我知道我可以膨胀布局xml,这可行,但我想知道我是否可以膨胀一项活动.例如,我有一个扩展Activity的类A和一个扩展ListActivity的另一个类B. 我可以在A级,我的B级包括和使用吗?这是我试过的:
A类:
LayoutInflater inflater = (LayoutInflater) MyActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate list
BActivity list = new BActivity();
Run Code Online (Sandbox Code Playgroud)
B级:
public class BActivity extends ListActivity {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
List<Model> models= new ArrayList<Model>();
models.add(new Model("John"));
models.add(new Model("Cage"));
setListAdapter(new MyAdapter(this, models));
ListView list = getListView();
}
}
Run Code Online (Sandbox Code Playgroud)
并在xml(类A xml)中:(我希望在哪里看到列表)
<view class="com.test.BActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" > </view>
Run Code Online (Sandbox Code Playgroud)
所有这些都会引发错误:
膨胀类BActivity时出错
活动在清单中声明.
你知道我做错了什么吗?这不是扩充另一项活动的正确方法吗?我使用的是Android 2.2 api 8.谢谢你的时间.
我已经在Android(树视图)中以编程方式构建了一个布局,现在我想在构建视图中添加一个topbar(topbar.xml).
所以我需要的不是:
setContentView(scroll)
Run Code Online (Sandbox Code Playgroud)
就像是:
inflateInMyViewCalledScroll(topbar.xml)
setContentView(scroll)
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议
我有两个Buttons主要布局.如果Button单击添加,则必须EditText动态添加(使用Inflater).这部分正在运作.如果Button单击" 删除" ,则必须先删除那些EditText带有最后一个的内容.但我不知道如何删除视图.
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.add_edit, null);
ll.addView(view);
}
});
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ll.removeViewAt(0);
}
});
Run Code Online (Sandbox Code Playgroud) android android-inflate viewgroup layout-inflater android-view
我正在尝试创建一个自定义视图 - 手指画,我遇到此错误的麻烦,我不知道如何解决它.谁能告诉我有什么问题?
logcat的:
08-04 08:34:01.171: E/AndroidRuntime(15664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.boenka.mk/com.boenka.mk.Draw}: android.view.InflateException: Binary XML file line #9: Error inflating class com.boenka.mk.DrawPanel
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.os.Looper.loop(Looper.java:137)
08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-04 08:34:01.171: E/AndroidRuntime(15664): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 08:34:01.171: E/AndroidRuntime(15664): at java.lang.reflect.Method.invoke(Method.java:511)
08-04 08:34:01.171: E/AndroidRuntime(15664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-04 08:34:01.171: E/AndroidRuntime(15664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-04 …Run Code Online (Sandbox Code Playgroud) android android-custom-view android-inflate android-canvas android-view
请帮帮我,这是我最近两天打砖墙,无法弄明白.
我有一个简单的PreferenceFragment,并希望从一个Activity中膨胀它.
这是res/xml/preferences.xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="preferences">
<PreferenceCategory
android:title="@string/notification_basic"
android:key="notification">
<CheckBoxPreference
android:key="enable_notification"
android:summary="@string/enable_notification"
android:title="@string/notification_title"
android:defaultValue="false">
</CheckBoxPreference>
<CheckBoxPreference
android:key="enable"
android:summary="@string/enable_instant_notification"
android:title="@string/notify_me_instantly"
android:dependency="enable_notification"
android:defaultValue="false">
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sign_up_notify_me_where_section"
android:key="locations">
<MultiSelectListPreference
android:dialogTitle="@string/sign_up_notify_me_where_title"
android:key="location"
android:summary="@string/sign_up_notify_me_where"
android:title="@string/sign_up_notify_me_where_title"
android:entries="@array/locations"
android:entryValues="@array/locations_values"
android:defaultValue="@array/empty_array"
android:dependency="enable_notification"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sign_up_notify_me_type_section"
android:key="types">
<MultiSelectListPreference
android:dialogTitle="@string/sign_up_notify_me_type_title"
android:key="type"
android:summary="@string/sign_up_notify_me_type"
android:title="@string/sign_up_notify_me_type_title"
android:entries="@array/types"
android:entryValues="@array/types_values"
android:defaultValue="@array/empty_array"
android:dependency="enable_notification"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sign_up_notify_me_who_section"
android:key="units">
<MultiSelectListPreference
android:dialogTitle="@string/sign_up_notify_me_who_title"
android:key="units"
android:summary="@string/sign_up_notify_me_who"
android:title="@string/sign_up_notify_me_who_title"
android:entries="@array/units"
android:entryValues="@array/units_values"
android:defaultValue="@array/empty_array"
android:dependency="enable_notification"
/>
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
活动:
public class HomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud) 好吧'我有一个RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@drawable/my_shape_normal"
android:onClick="startTestTillError">
Run Code Online (Sandbox Code Playgroud)
my_shape_normal定义为
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFFFF00"
android:endColor="#80FFFFFF"
android:angle="120"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
在加载时会引发异常:在RelativeLayout行的android.view.InflateException.如果我删除"android:background",一切都很完美.my_shape_normal出了什么问题?
我正在尝试使用动作模式获取上下文菜单,我可以通过长按它来选择ListView中的项目.我根据此引用创建了一个MultiChoiceListener,并创建了一个ItemLongClickListener,它将一个项设置为已选中,这是操作模式根据此引用工作所需的.
我的问题是,即使项目长时间点击动画正在播放,ActionMenu也不会膨胀.
ListView代码:
final ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(adapter);
listView.setLongClickable(true);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) {
Cursor cursor = db.getSubject(id);
String subject = null;
try {
subject = cursor.getString(cursor.getColumnIndex("subject"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent(Main.this, Marks.class);
intent.putExtra("selected", subject);
startActivity(intent);
}
});
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long …Run Code Online (Sandbox Code Playgroud) 我正在调用setLayoutData()许多地方的函数,我想在每次调用时清除视图.现在发生了什么布局得到追加.但是我不想追加我们如何清除视图.请帮助我这是我的功能
void setLayoutData() {
resultTrips = (LinearLayout) findViewById(R.id.trip_list);
LinearLayout.LayoutParams mainTripDetailsLayout = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LayoutInflater inflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0;i<4;i++) {
final LinearLayout tripdetailsdata = (LinearLayout) inflater
.inflate(R.layout.mytripinner, null);
tripdetailsdata.setId(i);
resultTrips.addView(tripdetailsdata);
i++;
}
TextView dummy = new TextView(this);
dummy.setLayoutParams(mainTripDetailsLayout);
resultTrips.addView(dummy);
}
Run Code Online (Sandbox Code Playgroud) 首先,请任何人可以告诉我是否可以在没有XML的情况下充气视图?
描述是这样的:
我通过编码动态生成了一个视图层次结构
Relative layout contain 4 Linear layouts -1st Linear Layout contain Image View -2nd Linear Layout contain surface view -3rd Linear Layout contain Button -4th Linear Layout contain Text Box
并且生成所有视图/视图层次结构没有问题(我通过调试和检查子视图进行测试)
但是我无法将其设置为setContent()
因为我没有XML而且不允许使用XML(不是确定为什么),即我无法访问R.Layout.所以我不能使用inflater.Inflate(R.Layout ...)
当我将主要相对布局设置为内容时,我收到以下错误
12-16 11:32:03.653: E/AndroidRuntime(22564): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package.class}: android.content.res.Resources$NotFoundException: Resource ID #0x1d97b
任何人都有任何想法?
----更新日志----
12-16 12:33:16.143: E/AndroidRuntime(25358): FATAL EXCEPTION: main
12-16 12:33:16.143: E/AndroidRuntime(25358): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package.class}: android.content.res.Resources$NotFoundException: Resource ID #0x1d97b
12-16 12:33:16.143: E/AndroidRuntime(25358): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
12-16 12:33:16.143: …
android ×10
android-inflate ×10
android-view ×2
xml ×2
action-menu ×1
background ×1
drawable ×1
graph ×1
listview ×1
viewgroup ×1