如何调整Scrollview的高度和宽度以适合多种屏幕分辨率

时间:2019-08-11 12:08:08

标签: android xml android-studio

正如标题所说,我在缩放Scrollview时遇到问题。

滚动视图包含多个按钮。 我在看起来不错的Google Pixel 3 XL上测试了我的应用程序,但在Pixel 2上看起来太大了,某些按钮无法访问,因为导航栏将它们悬停了。

这是我的XML代码:

const char* function1()
{
    lang = fopen("lang.csv", "r");
    int i = 0;
    char line[1024];
    const char* word[1024];
    char num[] = { 1 , 2 };
    while (fgets(line, 1024, lang))
    {
        char* tmp = _strdup(line);
        printf("Field 1 would be %s\n", getfield(tmp, num[0])); // NOTE strtok clobbers tmp
        word[i] = getfield(tmp, num[0]);
        i++; 
        free(tmp);
    }
    printf("%s\n", word[1]); //prints successfully
    fclose(lang);
    return NULL;
}

int function2() {
    const char* word[1024] = { function1() };
    printf("%s\n", word[1]); // failure, prints (null)
}

1 个答案:

答案 0 :(得分:0)

尝试在项目中添加尺寸值,并为每个对象提供适当的填充,无论它是按钮,文本还是其他任何东西。

创建一个dimens.xml文件夹并添加它,然后根据需要添加这些值

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="_minus1sdp">-1.00dp</dimen>
    <dimen name="_minus2sdp">-2.00dp</dimen>
    <dimen name="_minus3sdp">-3.00dp</dimen>
    <dimen name="_minus4sdp">-4.00dp</dimen>
    <dimen name="_minus5sdp">-5.00dp</dimen>
    <dimen name="_minus6sdp">-6.00dp</dimen>
    <dimen name="_minus7sdp">-7.00dp</dimen>
    <dimen name="_minus8sdp">-8.00dp</dimen>
    <dimen name="_minus9sdp">-9.00dp</dimen>
    <dimen name="_minus10sdp">-10.00dp</dimen>
    <dimen name="_minus11sdp">-11.00dp</dimen>
    <dimen name="_minus12sdp">-12.00dp</dimen>
    <dimen name="_minus13sdp">-13.00dp</dimen>
    <dimen name="_minus14sdp">-14.00dp</dimen>
    <dimen name="_minus15sdp">-15.00dp</dimen>
    <dimen name="_minus16sdp">-16.00dp</dimen>
    <dimen name="_minus17sdp">-17.00dp</dimen>
    <dimen name="_minus18sdp">-18.00dp</dimen>
    <dimen name="_minus19sdp">-19.00dp</dimen>
    <dimen name="_minus20sdp">-20.00dp</dimen>
    <dimen name="_minus21sdp">-21.00dp</dimen>
    <dimen name="_minus22sdp">-22.00dp</dimen>
    <dimen name="_minus23sdp">-23.00dp</dimen>
    <dimen name="_minus24sdp">-24.00dp</dimen>
    <dimen name="_minus25sdp">-25.00dp</dimen>
    <dimen name="_minus26sdp">-26.00dp</dimen>
    <dimen name="_minus27sdp">-27.00dp</dimen>
    <dimen name="_minus28sdp">-28.00dp</dimen>
    <dimen name="_minus29sdp">-29.00dp</dimen>
    <dimen name="_minus30sdp">-30.00dp</dimen>
    <dimen name="_minus31sdp">-31.00dp</dimen>
    <dimen name="_minus32sdp">-32.00dp</dimen>
    <dimen name="_minus33sdp">-33.00dp</dimen>
    <dimen name="_minus34sdp">-34.00dp</dimen>
    <dimen name="_minus35sdp">-35.00dp</dimen>
    <dimen name="_minus36sdp">-36.00dp</dimen>
    <dimen name="_minus37sdp">-37.00dp</dimen>
    <dimen name="_minus38sdp">-38.00dp</dimen>
    <dimen name="_minus39sdp">-39.00dp</dimen>
    <dimen name="_minus40sdp">-40.00dp</dimen>
    <dimen name="_minus41sdp">-41.00dp</dimen>
    <dimen name="_minus42sdp">-42.00dp</dimen>
    <dimen name="_minus43sdp">-43.00dp</dimen>
    <dimen name="_minus44sdp">-44.00dp</dimen>
    <dimen name="_minus45sdp">-45.00dp</dimen>
    <dimen name="_minus46sdp">-46.00dp</dimen>
    <dimen name="_minus47sdp">-47.00dp</dimen>
    <dimen name="_minus48sdp">-48.00dp</dimen>
    <dimen name="_minus49sdp">-49.00dp</dimen>
    <dimen name="_minus50sdp">-50.00dp</dimen>
    <dimen name="_minus51sdp">-51.00dp</dimen>
    <dimen name="_minus52sdp">-52.00dp</dimen>
    <dimen name="_minus53sdp">-53.00dp</dimen>
    <dimen name="_minus54sdp">-54.00dp</dimen>
    <dimen name="_minus55sdp">-55.00dp</dimen>
    <dimen name="_minus56sdp">-56.00dp</dimen>
    <dimen name="_minus57sdp">-57.00dp</dimen>
    <dimen name="_minus58sdp">-58.00dp</dimen>
    <dimen name="_minus59sdp">-59.00dp</dimen>
    <dimen name="_minus60sdp">-60.00dp</dimen>
</resources>

有关更多信息,您可以参考此link

它将引导您选择不同的屏幕尺寸。