Android 将屏幕分成两半,并将imageview放在两半上
我正在设计一个页面,但在这一点上卡住了。如果有人知道,请告诉我。 我想这样做:Android 将屏幕分成两半,并将imageview放在两半上,android,android-layout,android-imageview,android-relativelayout,Android,Android Layout,Android Imageview,Android Relativelayout,我正在设计一个页面,但在这一点上卡住了。如果有人知道,请告诉我。 我想这样做: 放置带有圆形正方形的鸟形图像。您可以在此处找到解决方案: 如果需要,可以使用以下代码: int finalHeight, finalWidth; final ImageView iv = (ImageView)findViewById(R.id.scaled_image); final TextView tv = (TextView)findViewById(R.id.size_label); ViewTreeO
放置带有圆形正方形的鸟形图像。您可以在此处找到解决方案: 如果需要,可以使用以下代码:
int finalHeight, finalWidth;
final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
final TextView tv = (TextView)findViewById(R.id.size_label);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
iv.getViewTreeObserver().removeOnPreDrawListener(this);
finalHeight = iv.getMeasuredHeight();
finalWidth = iv.getMeasuredWidth();
tv.setText("Height: " + finalHeight + " Width: " + finalWidth);
return true;
}
});
如果这有帮助的话,也只是一个想法,您可以将图像分成两部分,并将它们与布局对齐,如将底部对齐和将顶部与各自的布局对齐
对于圆角背景,您可以在可绘制文件夹中创建bg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
祝你好运
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.testing.MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#0000ff"
android:orientation="vertical"
android:layout_weight="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#00ffff"
android:orientation="vertical"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:orientation="vertical"
android:background="#00ff00"
android:layout_gravity="center" />
</FrameLayout>
看起来像这样
自从两年前我发布这篇文章以来,我看不到任何有用的答案,所以我自己来回答 通过使用
布局锚定
和布局锚定重力
可以在协调布局
中完成,我们可以将一个视图
锚定到另一个视图
。它非常简单,因为它是协调布局的内置行为
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyActivity">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="180dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/img_banner" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_logo"
app:layout_anchor="@id/header"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
您可以使用布局组件以像素或百分比分割屏幕,并将其用作锚定来固定任何其他组件。下部应根据布局内容在高度上可拉伸。您可以在下部线性布局下使用scrollview,但上部也应随之向上移动。然后您应使用坐标布局。以下链接可能对您有所帮助。我想,就是这样。