我有一个相当简单的布局:ConstraintLayout填充整个屏幕,一个大的CardView,在顶部,有ImageView一半在CardView它上面一半(实际上不是一半,但你明白了).
然而,有两个问题:ImageView父母左边的棍子,我不知道如何使它水平居中 - 我在谷歌上找到的只是多个元素的链,但我只想要一个居中.
布局编辑器对我来说非常糟糕.我的第一个抱怨是我似乎无法为父母创建约束.然后我尝试ImageView通过按下"父母中心"按钮在父母水平居中.这增加了CardView宽度,完全没有效果ImageView.
当我在它的时候,我怎么能在它ImageView上面排序CardView?
这里的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="32dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="160dp"
app:cardCornerRadius="12dp"
app:cardElevation="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.CardView>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="40dp"
android:scaleType="centerCrop"
android:src="@drawable/re_zero"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)
谢谢!
我试图扭转一个字符串到位.
void reverseStr(char *str)
{
int i;
int length;
int last_pos;
length = strlen(str);
last_pos = length-1;
for(i = 0; i < length / 2; i++)
{
char tmp = str[i];
str[i] = str[last_pos - i];
str[last_pos - i] = tmp;
}
}
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400893 in reverseStr (str=0x400974 "Haus") at main.c:102
102 str[i] = str[last_pos - i];
(gdb) print i
$1 = 0
(gdb) print last_pos
$2 = 3
(gdb) print str
$3 = 0x400974 …Run Code Online (Sandbox Code Playgroud)