在ImageView内部居中放置图像,该图像将宽度和高度设置为match_parent
ImageView
<ImageView
android:adjustViewBounds="true"
android:id="@+id/iv_Image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scaleType="matrix"
android:src="@drawable/test_image" />
由于使用了缩放和触摸事件,scaleType设置为“矩阵”。
如何在ImageView中居中放置图像。
答案 0 :(得分:1)
首先获取设备的宽度和高度
...
@Controller("/**")
public class MainController {
@Get(value="/path1")
public HttpResponse handlePath1Get(HttpRequest<?> request) {
.. do something ..
}
@Get(value="/path1/action1")
public HttpResponse handlePath1Action1(HttpRequest<?> request) {
.. do something else ..
}
}
使用image_width计算ImageView CenterX
<b:skin>
.post1{
background-color: black;
color: white;
margin: 20px;
padding: 20px;
width: 350px;
float:right
}
.post2{
background-color: black;
color: white;
margin: 20px;
padding: 20px;
width: 350px;
float:left
}
</b:skin>
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="post-wrapper">
<div class="post1">
<b:section class='main' id='main' showaddelement='no'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog' version='1'/>
</b:section>
</div>
<div class="post2">
<b:section class='main' id='main1' showaddelement='no'>
<b:widget id='Blog2' locked='true' title='Blog Posts' type='Blog' version='2'/>
</b:section>
</div>
</div>
</div>
使用image_height计算ImageView CenterY
DisplayMetrics displayMetrics = new DisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
将“新矩阵”设置为“图像”
float imageCenterX = (displayMetrics.widthPixels - image_width) / 2;