我正在通过扩展LinearLayout创build一个自定义小部件: public class MyWidget extends LinearLayout { private static Paint PAINT = new Paint(Paint.ANTI_ALIAS_FLAG); static { PAINT.setColor(Color.RED); } public MyWidget(Context context) { this(context, null); } public MyWidget(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight()/2, canvas.getWidth()/2, PAINT); // never gets called 🙁 } @Override protected […]
我有多个LinearLayout ,组合高度很容易超过设备的屏幕高度。 所以为了使我的布局可滚动,我尝试添加一个ScrollView ,但不幸的是我得到以下错误: Scrollview只能托pipe一个直接的孩子 我做了一些研究,但是即使阅读了一些解决scheme之后,也不能真正理解如何解决这个问题。 我尝试了一些改变,但到目前为止,没有任何工作。 任何帮助? <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingTop="20dip"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Question 1" android:paddingBottom="20dip" android:gravity="center" /> <TextView android:id="@+id/q1_score" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" android:gravity="center"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Question 2" android:paddingBottom="20dip" android:gravity="center" /> <TextView android:id="@+id/q2_score" android:layout_width="0dp" […]
我有一个线性布局内的文本视图。 现在我想在java中删除这个文本视图。 这个文本视图是dynamic生成的。 我有线性布局的ID。 如何清空线性布局内的所有内容? <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/myid"> <TextView …/> <TextView …/> <TextView …/> </LinearLayout>
我创build一个线性布局,引用一个XML项目。 在这个linearlayout里面我dynamic地放了一些textview,所以不用从xml中取出它们。 现在我需要从linearlayout中删除这些textviews。 我试过这个: if(((LinearLayout) linearLayout.getParent()).getChildCount() > 0) ((LinearLayout) linearLayout.getParent()).removeAllViews(); 但它不起作用。 我能怎么做? 谢谢,Mattia
我试图添加一个头到ExpandableListView像这样: headerView = View.inflate(this, R.layout.header, null); expandableListView.addHeaderView(headerView); expandableListView.setAdapter(new SectionedAdapter(this)); 这给了我以下错误: 12-08 16:23:42.354: ERROR/AndroidRuntime(421): Caused by:java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ListView.clearRecycledState(ListView.java:504) 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ListView.resetList(ListView.java:490) 12-08 16:23:42.354:ERROR/AndroidRuntime(421):at android.widget.ListView.setAdapter(ListView.java:422) 12-08 16:23:42.354:ERROR/AndroidRuntime(421): at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:475) 这发生在调用expandableListView.setAdapter(new SectionedAdapter(this)) ,但我不明白为什么。 有任何想法吗?
想要用两个LinearLayouts为我的应用程序分割一个屏幕。 我应该使用什么参数来精确分割两个相等的部分 – 第一个是LinearLayout,第二个是在它的下面。
如何设置ViewGroup的最大宽度? 我正在使用一个Theme.Dialog活动,但是,当调整到更大的屏幕时,这看起来不太好,它也是轻量级的,我不希望它占据整个屏幕。 我试过这个build议无济于事。 此外,没有像某些视图的android:maxWidth属性。 有没有办法限制根LinearLayout,以便它只是(例如)640浸? 我愿意为此更换为另一个ViewGroup。 有什么build议么?
我有一个TextView ,我想要在垂直排列的元素使用LinearLayout横向活动的底部。 我已经在文本视图上设置了android:gravity="bottom" ,但它仍然只是低于LinearLayout的最后一个元素,正是我不想要的。 有什么build议么?
我想知道是否可以将每个单独的RadioButton分组在一个独特的RadioGroup保持相同的结构。 我的结构是这样的: LinearLayout_main LinearLayout_1 RadioButton1 LinearLayout_2 RadioButton2 LinearLayout_3 RadioButton3 正如你所看到的,现在每个RadioButton都是不同的LinearLayout的子LinearLayout 。 我尝试使用下面的结构,但它不工作: radioGroup中 LinearLayout_main LinearLayout_1 RadioButton1 LinearLayout_2 RadioButton2 LinearLayout_3 RadioButton3
我有一个大的布局,一个更小的布局里面。 如何在小布局周围创build线边框?