Set ImageView's max width as a percent of its parent's width

前端 未结 1 1996
星月不相逢
星月不相逢 2020-12-01 16:35

I\'m loading navigation from a website, where each item has a title, description, and image. I want to have all of the titles and descriptions centered along the same axis.<

相关标签:
1条回答
  • 2020-12-01 16:51

    This can't be done in the XML. You would have to specify the size in the code. I would do that in the onCreate() of the activity:

    import android.widget.LinearLayout.LayoutParams;
    ...
    obj.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                         LayoutParams.WRAP_CONTENT,
                                         0.25f));
    

    This means use 100% of the parent's height but 25% of the parent's width.

    0 讨论(0)
提交回复
热议问题