优化ImageFit.Auto的demo,使用滚动条调整宽度,体现高度的自适应
Signed-off-by: madixin <42690727@qq.com>
This commit is contained in:
parent
f709bd3f01
commit
3378d36046
|
@ -12,49 +12,47 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {
|
import { ImageKnifeComponent } from '@ohos/libraryimageknife';
|
||||||
ImageKnifeComponent,
|
import { display } from '@kit.ArkUI';
|
||||||
ImageKnifeData,
|
|
||||||
ImageKnifeRequest, LogUtil
|
|
||||||
} from '@ohos/libraryimageknife';
|
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct AutoImageFit {
|
struct AutoImageFit {
|
||||||
@State width1: Length = '100%'
|
@State imageWidth: number = 200;
|
||||||
|
private maxWidth: number = px2vp(display.getDefaultDisplaySync().width);
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
|
||||||
|
Column() {
|
||||||
|
this.Slider()
|
||||||
Column() {
|
Column() {
|
||||||
Button($r('app.string.adjust_size')).onClick(() => {
|
|
||||||
if (this.width1.toString() == '100%') {
|
|
||||||
this.width1 = '60%'
|
|
||||||
} else {
|
|
||||||
this.width1 = '100%'
|
|
||||||
}
|
|
||||||
}).width('100%')
|
|
||||||
Text('Image')
|
Text('Image')
|
||||||
Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg').width('100%').objectFit(ImageFit.Auto)
|
Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg')
|
||||||
|
.width('100%')
|
||||||
|
.objectFit(ImageFit.Auto)
|
||||||
Text('ImageKnife')
|
Text('ImageKnife')
|
||||||
ImageKnifeComponent({
|
ImageKnifeComponent({
|
||||||
imageKnifeOption: {
|
imageKnifeOption: {
|
||||||
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
|
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
|
||||||
objectFit: ImageFit.Auto,
|
objectFit: ImageFit.Auto,
|
||||||
onLoadListener: {
|
|
||||||
onLoadStart: (request?: ImageKnifeRequest) => {
|
|
||||||
LogUtil.info('onLoadStart')
|
|
||||||
},
|
|
||||||
onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData,
|
|
||||||
request?: ImageKnifeRequest) => {
|
|
||||||
LogUtil.info('onLoadSuccess')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).width('100%')
|
}).width('100%')
|
||||||
|
}.width(this.imageWidth).border({ width: 1 })
|
||||||
}.width(this.width1).border({ width: 1 })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
Slider() {
|
||||||
|
Slider({
|
||||||
|
value: this.imageWidth,
|
||||||
|
min: 100,
|
||||||
|
max: this.maxWidth,
|
||||||
|
style: SliderStyle.OutSet
|
||||||
|
})
|
||||||
|
.blockColor(Color.White)
|
||||||
|
.width('100%')
|
||||||
|
.onChange((value: number) => {
|
||||||
|
this.imageWidth = value;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue