我有15個textView元素,我想在另一個之下對齊。但是當屏幕尺寸縮小時,一些textView消失。我該如何安排? (我一直在使用RelativeLayout,如果有與其他人解決的Layouts,你可以解釋一下)如何根據屏幕大小安排我的textViews?
0
A
回答
0
您可以創建自己的佈局。
如果沒有足夠的空間,此佈局將自動流動下一行。 像浮動:留在HTML/CSS
public class PredicateLayout extends ViewGroup {
private int line_height;
public PredicateLayout(Context context) {
super(context);
}
public PredicateLayout(Context context, AttributeSet attrs){
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
assert(MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED);
final int width = MeasureSpec.getSize(widthMeasureSpec);
// The next line is WRONG!!! Doesn't take into account requested MeasureSpec mode!
int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom();
final int count = getChildCount();
int line_height = 0;
int xpos = getPaddingLeft();
int ypos = getPaddingTop();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
child.measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
final int childw = child.getMeasuredWidth();
line_height = Math.max(line_height, child.getMeasuredHeight() + lp.height);
if (xpos + childw > width) {
xpos = getPaddingLeft();
ypos += line_height;
}
xpos += childw + lp.width;
}
}
this.line_height = line_height;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED){
height = ypos + line_height;
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST){
if (ypos + line_height < height){
height = ypos + line_height;
}
}
setMeasuredDimension(width, height);
}
@Override
protected LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(30, 30); // default of 1px spacing
}
@Override
protected boolean checkLayoutParams(LayoutParams p) {
return (p instanceof LayoutParams);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
final int width = r - l;
int xpos = getPaddingLeft();
int ypos = getPaddingTop();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final int childw = child.getMeasuredWidth();
final int childh = child.getMeasuredHeight();
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (xpos + childw > width) {
xpos = getPaddingLeft();
ypos += line_height;
}
child.layout(xpos, ypos, xpos + childw, ypos + childh);
xpos += childw + lp.width;
}
}
}
}
1
但是當屏幕尺寸變窄時,一些textView消失。我如何 安排?
使用ScrollView
使UI可以滾動。
+1
艾哈邁德是正確的,你想換行,滾動型佈局。 –
+0
謝謝......我可以修改而不使用ScrollView嗎? –
相關問題
- 1. 如何根據窗口大小安排屏幕
- 2. 安卓:根據屏幕大小
- 3. 如何根據屏幕大小
- 4. 根據屏幕大小在CSS中安排元素
- 5. jQuery的,如果根據屏幕大小
- 6. Swift如何根據屏幕大小調整元素的大小
- 7. 如何根據屏幕大小調整.swf文件的大小?
- 8. 如何根據屏幕大小更改圖像大小?
- 9. 如何根據設備屏幕大小設置div大小?
- 10. 如何根據屏幕大小更改字體大小
- 11. 如何讓我的影片剪輯根據屏幕大小調整大小?
- 12. 我如何設置「div」大小根據手機屏幕方向
- 13. 根據屏幕大小重新排列DOM的最佳方法
- 14. 根據屏幕大小刪除列
- 15. UICollectionViewCell根據屏幕/ FrameSize大小Swift
- 16. 根據屏幕大小執行PHP
- 17. 根據屏幕大小更改網頁
- 18. 根據屏幕大小隱藏視圖。
- 19. 根據屏幕尺寸縮小字體大小/邊距大小?
- 20. 根據libgdx中的屏幕大小設置actor大小
- 21. 根據屏幕大小調整WPF窗口的大小
- 22. 使按鈕的大小根據屏幕大小使用jquery/javascript
- 23. 根據屏幕大小調整ImageView的大小 - Android
- 24. JPanel的位置和大小根據屏幕大小而變化
- 25. 根據Android上的屏幕大小調整圖像大小
- 26. 如何根據屏幕調整div與圖像的大小?
- 27. 如何根據屏幕調整滑塊圖像的大小
- 28. 如何根據屏幕分辨率調整div的大小
- 29. 如何根據iPhone的屏幕大小更改UIWebView?
- 30. 如何根據Sprite Kit中的設備更改屏幕大小?
我會試試看。謝謝... –