我们正在编写一个针对ICS +的应用程序,并认为GridLayout是最好的布局范例,但似乎很少有关于它的文章,我们遇到了一些对齐问题.
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_background"
android:rowCount="1"
android:columnCount="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
android:background="@drawable/list_item_bg">
<ImageView
android:id="@+id/visibilityIcon"
android:layout_row="0"
android:layout_column="0"
android:src="@drawable/visibility_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<ImageView
android:id="@+id/windIcon"
android:layout_row="0"
android:layout_column="1"
android:src="@drawable/wind_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<ImageView
android:id="@+id/crosswindIcon"
android:layout_row="0"
android:layout_column="2"
android:src="@drawable/cloud_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
</GridLayout>
Run Code Online (Sandbox Code Playgroud)
但是,左侧2图标保持左对齐,最右侧图标以剩余空间居中.
基本上我们需要做的是将每列的大小指定为总屏幕大小的1/3(自3列).我认为这就是GridLayout所做的,但看起来'wrap_content'会导致这种行为(有意义),但'match_parent'会导致第一列填满整个屏幕,而不是填充其单元格,这是我预期的行为.
我们似乎已经尝试过重力,layout_gravity等的所有组合,但要么我们从根本上做错了什么,要么发现了GridLayout的限制.
谢谢你的帮助!
android alignment grid-layout xml-layout android-4.0-ice-cream-sandwich
由于viewpager,我无法滚动nestedScrollView.那么让我在这里解释一下我想要创建的布局设计:
NestedScrollView中有FrameLayout,标签布局有viewpager.Viewpager用无尽的recylerview(Pagination)加载三个片段.
这是布局xml代码:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="com.plowns.droidapp.activites.HomeActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:background="@color/colorPrimary" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@color/trans">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="260dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="55dp"
app:cardCornerRadius="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/txt_edit_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_mode_edit"
android:tint="@color/blue_plowns" />
<TextView
android:id="@+id/txt_child_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ellipsize="end"
android:gravity="center_vertical"
android:minHeight="5dp"
android:text="Satwinder Singh"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@android:color/black"
android:textSize="18sp" …Run Code Online (Sandbox Code Playgroud) android android-layout xml-layout android-viewpager android-nestedscrollview
我正在学习自定义组件,我在使用自定义xml属性时遇到了一些麻烦.
我的自定义组件扩展了LinearLayout,在构造函数(public Custom(Context context, AttributeSet attrs))中我正在膨胀xml布局(2个按钮和1个EditText).
我也在values/attrs这个自定义属性中声明:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Custom">
<attr name="initValue" format="integer" />
<attr name="stepSize" format="integer" />
<attr name="maxValue" format="integer"/>
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
在我膨胀布局后的构造函数中,我正在尝试读取这样的自定义属性:
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(attrs,
R.styleable.Custom, 0, 0);
setInitValue(ta.getInt(R.styleable.Custom_initValue, 0));
setStepSize(ta.getInt(R.styleable.Custom_stepSize, 1));
setMaxValue(ta.getInt(R.styleable.Custom_maxValue, 5));
ta.recycle();
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试通过将其添加到xml布局来测试此自定义组件,如下所示:
<?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">
<here.is.my.package.Custom android:id="@+id/add"
android:layout_width="wrap_content" android:layout_height="wrap_content"
initValue="2" maxValue="7" stepSize="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这不起作用,我只得到默认值(0,1,5).我错过了什么或这是正常的行为?
在我的android项目的/ res/values文件夹中,我有一个字符串,并在我的xml文件的文本视图中引用,我想更改我的java文件中的字符串.
正如您在下面的代码中看到的,我已经创建了一个字符串变量,然后在下面我已经设置了字符串变量设置的内容,这是字符串所在的位置.我在代码中提出"here",我想在values文件夹中更改为字符串.但我不知道用什么代码来设置它.
我可以从我的java文件中更改文本视图中的文本,我知道该怎么做,但这是一种旧的方式,它设置了一个警告,所以我宁愿使用字符串,这是最好的方法.
凭借我在文本视图中更改文本的知识,我基本上已经猜到了进入这个阶段的方式,但我不知道如何进一步,任何人都可以给我一些建议,谢谢.
String string;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter = 0;
add = (Button) findViewById(R.id.badd);
sub = (Button) findViewById(R.id.bsub);
reset = (Button) findViewById(R.id.breset);
display = (TextView) findViewById(R.id.tvdisplay);
string = (String) getString(R.string.counter);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
((///////////////here////////////////))
counter++;
}
});
Run Code Online (Sandbox Code Playgroud) 我收到了这种警告
如果@ id/order_row_date由于本地化文本扩展而增长,则@ id/order_row_date可以重叠@ id/order_row_amout.
如果相对布局具有与左侧和右侧对齐的文本或按钮项,则它们可以由于本地化文本扩展而彼此重叠,除非它们具有诸如toEndOf/toStartOf之类的相互约束.
我的XML文件是:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/order_row_lower_layout"
android:layout_below="@+id/order_row_upper_layout"
android:layout_toEndOf="@+id/order_row_box_layout"
android:layout_toRightOf="@+id/order_row_box_layout"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/order_row_amout"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_normal"
android:textColor="@color/color_gray"
android:textStyle="bold"
android:text="50000"
tools:text="@string/string_amout_with_ruppe" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/order_row_date"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:textColor="@color/color_gray"
tools:text="08/09/2016" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
有人知道这种警告吗?
提前欣赏:)
android warnings android-layout xml-layout android-relativelayout
我有一个命名的片段HostFragment,它嵌套了一到四个其他片段.
这是布局HostFragment:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hostFragmentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/fragmentContainer1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RelativeLayout
android:id="@+id/fragmentContainer2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/fragmentContainer3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RelativeLayout
android:id="@+id/fragmentContainer4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
其中重要的部分是android:layout_marginTop="12dp".
背景:嵌套片段覆盖HostFragment除此边距之外的整体.当嵌套片段改变其背景颜色(通过调用Canvas#drawColor)时,HostFragment还需要更改此边距的颜色以匹配.我存储了所需的颜色SharedPreferences.
行为:如果用户从去HostFragment到SettingsActivity,改变颜色,并且回来HostFragment,嵌套的片段将立即(通过他们改变自己的颜色onResume()的方法),但HostFragment"保证金将仍然是旧的颜色.如果用户然后离开HostFragment并转到另一个片段,然后返回HostFragment,则边距将更新其颜色.我不知道如何或为什么 - 我没有代码HostFragment来更新颜色.该代码HostFragment …
我想在 a中将errorEnabled和 都设置为 true ,但似乎这两者不能共存,因为一个像这样覆盖另一个。passwordToggleEnabledTextInputLayout
我想这样做是因为我正在验证密码字段以匹配特定条件,并且我希望用户能够看到错误消息和已输入的密码。
这是我的代码:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:errorEnabled="true"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
是否可以将密码切换图标移到感叹号左侧一点?或者我是否必须创建一个自定义可绘制对象并使用它而不是密码切换图标?
更新后com.google.android.material:material,androidx.constraintlayout:constraintlayout从 1.1.0 和 1.1.3 到 1.3.0 和 2.0.4,我的布局被压扁了。我在 ScrollView->LinearLayout 中有一个自定义视图约束布局。问题是,更新所述依赖项后,视图会被压扁,并且不再使用wrapp_content来声明它需要的高度。(预览与运行版本匹配,缓存清除/重建没有帮助。)
我可能搞砸了一些东西,但不知道到底是什么。
片段布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:orientation="vertical">
<my.app.ui.editor.AssetAttributeView
android:id="@+id/assetName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:label="@string/hint_asset_name" />
<!-- and some more of them.. -->
</linearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
自定义视图布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/editor_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/asset_attribute_view_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:labelFor="@id/asset_attribute_view_text"
android:saveEnabled="false"
android:text="@string/PLACEHOLDER"
app:layout_constraintBottom_toBottomOf="@+id/asset_attribute_view_switch"
app:layout_constraintEnd_toStartOf="@+id/asset_attribute_view_switch"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/asset_attribute_view_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:ems="10" …Run Code Online (Sandbox Code Playgroud) 网络上关于带有 XMLLayout 的 log4j2 的信息非常少。
我没有找到任何带有简单示例的链接(log4j2 + XMLLayout);
有人可以发布一个相同的简单示例....
关于 Karthik
我正在尝试在 jetpack compose 中使用一些片段,但无法从 (androidx.compose.ui.viewinterop) 导入 AndroidViewBinding,并且它始终显示为未解析的名称
怎么导入呢??
xml-layout android-jetpack-compose android-viewbinding composable
xml-layout ×10
android ×8
alignment ×1
android-4.0-ice-cream-sandwich ×1
composable ×1
grid-layout ×1
log4j2 ×1
string ×1
textview ×1
typedarray ×1
warnings ×1