如何在水平LinearLayout中制作4个固定大小的按钮水平填充该图层的空间,让Android在这些按钮之间填充所需空间以填充该空间?
android autofill gravity android-layout android-linearlayout
我在Realtive Layout中有ImageView和textview.相对布局的Onclcik我需要获取文本View的值并需要更改imageview.获得空指针异常.这是守则
活动代码
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int id=0;
for (int idx = 0; idx < dataFromDb.size(); idx++) {
id = idx + 1;
rel = (RelativeLayout) inflater.inflate(
R.layout.newdata, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 50, 0, 0);
txt = (TextView) rel.findViewById(R.id.fetchData);
txt.setText(dataFromDb.get(idx));
txt.setId(id);
img = (ImageView) rel.findViewById(R.id.tickbox);
img.setImageResource(R.drawable.tickbox1a);
img.setId(id);
rel.setOnClickListener(new ImageView.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(DoTask.this,
"Selected" + v.getId(),
Toast.LENGTH_LONG).show();
RelativeLayout im=(RelativeLayout)v;
ImageView i=(ImageView)im.findViewById(im);
i.setImageResource(R.drawable.tickbox1b);
}
});
content.addView(rel, …Run Code Online (Sandbox Code Playgroud) 这段代码正在扼杀我.我试图以LinearLayout编程方式设置(包含子项)的宽度和高度,应用程序正在打破.这是代码:
LinearLayout ll = (LinearLayout) findViewById(R.id.right_t);
ll.setLayoutParams(new android.widget.LinearLayout.LayoutParams(200, 200));
Run Code Online (Sandbox Code Playgroud)
如你所见,我100%确定我可以使用正确的布局框架.然而,该应用程序打破了错误
1-22 19:54:13.135: ERROR/AndroidRuntime(4560): FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
at android.widget.RelativeLayout$DependencyGraph.findRoots(RelativeLayout.java:1317)
at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1264)
at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:292)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:314)
at android.view.View.measure(View.java:12863)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12863)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:12863)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2256)
at android.view.View.measure(View.java:12863)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1197)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2585)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native …Run Code Online (Sandbox Code Playgroud) 我正在解析一个json后开发一个ListView UI,我们正在寻找一个基于模板的解决方案来列出行,其中每个列表行可能有不同的2字段,它们的对齐方式将由服务器以json的形式驱动.我已经解析了我的JSON并为ListView开发了行,如下所示

但是我无法在linearLayout中对齐我的视图,比如Name应该在大多数左边,而rest视图应该是右对齐的,例如我们在XML UI中完成的.

任何人都可以帮我在LinearLayout的上面listView中对齐这些viwes就像我的XML视图一样.
我添加几个水平方向的linearLayout并在这些布局中添加所有子视图,添加所有子项后,我将此布局添加到另一个具有垂直方向的LinearLayout中.
我已经尝试过了
在LinearLayout中添加视图时传递RelativeLayout和LinearLayout限定的参数以进行对齐,但它不起作用,我可以从左侧或右侧添加视图.
这是我的代码,我尝试添加视图来为List创建一行.
public class RowLayout extends LinearLayout{
Context context;
Hashtable<String, LinearLayout> ht = new Hashtable<String, LinearLayout>();
LinearLayout ll;
WorkkardData workkardData=null;
public RowLayout(Context context) {
super(context);
this.context=context;
}
public LinearLayout generateLayout(Object object, WorkkardData workkard){
this.workkardData=workkard;
JSONObject json = (JSONObject)object;
String template="";
String cardBackground="";
String cardSelectedBackground="";
String fieldName="";
try {
template = json.getString("templateId");
} catch (Exception e) {
}
try {
cardBackground = json.getString("backgroundColor");
} catch (Exception e) {
e.printStackTrace();
}
try {
cardSelectedBackground = …Run Code Online (Sandbox Code Playgroud) user-interface android json android-layout android-linearlayout
我一定是错过了一些非常愚蠢的东西.
我在视图中有一个LinearLayout:
_editTextViews = (LinearLayout)findViewById(R.id.editDesAndLocViews);
Run Code Online (Sandbox Code Playgroud)
我试图height通过设置动态更改该视图LayoutParams
我有两个 LinearLayout.LayoutParams
LinearLayout.LayoutParams collapsedParams;
LinearLayout.LayoutParams openParams;
Run Code Online (Sandbox Code Playgroud)
在构造函数中设置如下:
collapsedParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,0);
openParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)
但是一旦我尝试将其中一个参数应用到我的身上LinearLayout,就像这样:
_editTextViews.setLayoutParams(collapsedParams);
Run Code Online (Sandbox Code Playgroud)
我得到以下致命异常:

起初我认为我的项目需要清理,因为它似乎认为我试图强制相对布局使用线性布局参数,但一切都是LinearLayout.有问题的LinearLayout确实包含一对RelativeLayouts.我不知道是否/为什么会出现这个问题.
请帮忙
我有一个配置文件页面包含一个linearlayout,其中包含一些textview和imageview以及listview.(见图)

问题是我想让整个页面像在twitter应用程序中一样滚动,而不仅仅是listview.因此listview需要扩展到最大高度.
如何强制列表视图扩展到最大大小而不是可滚动.
我的linearlayout将是第二个选项,但是它需要可以添加自定义arrayadapter和listview中的自定义行.
这是我的linearLayout:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ANNULLA"
android:id="@+id/button4"
android:layout_gravity="bottom"
android:textColor="#FFF"
android:background="#87a914"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="3dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SALVA"
android:id="@+id/button5"
android:layout_gravity="bottom"
android:textColor="#FFF"
android:background="#87a914"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginBottom="2dp"
android:layout_marginRight="3dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
结果如下:

我想在按钮"SALVA"和按钮"ANNULLA"之间有一个空格
我的意思是这样的:

我有以下xml布局 - 如果editText_model文本相当短,则表格按重量值分割50/50.
然而,文本得到的时间越长,它就越夸大单词Description.为什么忽略了50/50的分裂?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:paddingLeft="5dp"
android:text="Select"
android:textSize="15sp"/>
<RadioGroup
android:id="@+id/radioGroupAdd"
android:layout_weight="50"
android:orientation="horizontal">
<RadioButton
android:id="@+id/RadioModel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test1"/>
<RadioButton
android:id="@+id/RadioPaint"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Test2"/>
</RadioGroup>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<TableRow>
<TextView
android:id="@+id/tV_model"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:gravity="center|left"
android:paddingLeft="5dp"
android:text="Description"
android:textSize="15sp"/>
<EditText
android:id="@+id/editText_model"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:hint="Enter Description"
android:inputType="text|textMultiLine|textNoSuggestions"
android:minLines="3"
android:text="testing long line of text 1234567890 123 456 77878 89 9 9d"
android:textSize="15sp"/>
</TableRow>
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我有一个标题为"status2.xml"的布局,其代码发布在下面.我有一个名为"meine_vertaege.xml"的主要版面,其代码也在下面发布."act_main.xml"包括上述布局,即"status2.xml"和"meine_vertaege.xml".
我在"act_main.xml"中包含"status2.xml"和"meine_vertaege",如下面"act_main.xml"的代码所示.
我遇到的问题是当我在"act_main.xml"中包含"status2.xml"和"meine_vertaege"时,我无法看到"status2.xml"的全部内容,因为它似乎是"status2.xml"的内容"和"meine_vertaege.xml"混淆了
请让我知道如何在"act_main.xml"中包含"status2.xml"和"meine_vertaege",这样我就可以看到它们的全部内容,使它们垂直组织
status2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
android:paddingStart="10dp"
android:gravity="center_vertical"
android:text="Status"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="3dp"
android:layout_weight="5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
android:paddingStart="10dp"
android:text="vertraege"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
status2.xml的输出:
meine_vertaege.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actMain_meine_vertraege_layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="@dimen/padding">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/gray"
android:gravity="center_vertical|start"
android:paddingStart="@dimen/padding"
android:text="Meine Verträge" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/actMain_lisVie"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
meine_vertaege.xml的输出:
act_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) 我的底部布局有问题,我的约束布局没有完全填满滚动视图(下面是空白)。这是问题的图像证据。在这种情况下,我希望灰色背景填充下面的白色空间。我在所有方面都尝试过比赛父母,但它不起作用。
这是我的xml文件,属于我上传的布局
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout">
<data>
<variable
name="viewModel"
type="com.repsol.repsolmove.ui.login.LoginViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/scrolView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="174dp"
android:layout_height="70dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="3dp"
android:src="@drawable/ic_img_logo_repsolmove"
app:layout_constraintBottom_toTopOf="@+id/imageBottomMargin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.repsol.repsolmove.ui.widgets.RepsolInputLayout
android:id="@+id/login"
android:layout_width="0dp"
android:layout_height="105dp"
android:layout_marginTop="30dp"
app:errorText="@string/invalid_card_number"
app:layout_constraintEnd_toStartOf="@+id/marginEnd"
app:layout_constraintStart_toStartOf="@+id/marginStart"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:titleText="@string/login_title" />
<com.repsol.repsolmove.ui.widgets.RepsolInputLayout
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="105dp"
app:errorText="@string/invalid_password"
app:isPassword="true"
app:layout_constraintEnd_toStartOf="@+id/marginEnd"
app:layout_constraintStart_toStartOf="@+id/marginStart"
app:layout_constraintTop_toBottomOf="@+id/login"
app:titleText="@string/password_title" />
<TextView
android:id="@+id/newPassword"
style="@style/RepsolText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:fontFamily="@font/repsol_regular"
android:text="@string/new_password"
android:textSize="16dp"
app:layout_constraintEnd_toStartOf="@+id/marginEnd"
app:layout_constraintTop_toBottomOf="@+id/password" />
<Button
android:id="@+id/btnLogin"
android:layout_width="228dp"
android:layout_height="50dp"
android:layout_marginStart="8dp" …Run Code Online (Sandbox Code Playgroud)